ThreeImageTableViewCell.m 3.47 KB
//
//  ThreeImageTableViewCell.m
//  SCIOLiveCN
//
//  Created by huayu on 17/2/13.
//  Copyright © 2017年 huayu. All rights reserved.
//

#import "ThreeImageTableViewCell.h"

@implementation ThreeImageTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        _backGroundView = [[UIView alloc] initWithFrame:CGRectMake(12, 6, MainScreenWidth - 24, threeImageCellWidth*5/8 + 50)];
        _backGroundView.backgroundColor = [UIColor whiteColor];
        [self addSubview:_backGroundView];
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 6, MainScreenWidth - 30, 30)];
        _titleLabel.textColor = HEXCOLOR(0x333333);
        _titleLabel.font = [UIFont systemFontOfSize:16];
        _titleLabel.backgroundColor = [UIColor clearColor];
        [self addSubview:_titleLabel];
        
        _leftImage = [[UIImageView alloc] initWithFrame:CGRectMake(16, 36, threeImageCellWidth, threeImageCellWidth*5/8)];
        _leftImage.contentMode = UIViewContentModeScaleAspectFill;
        _leftImage.layer.masksToBounds = YES;
        [self addSubview:_leftImage];
        
        _midleImage = [[UIImageView alloc] initWithFrame:CGRectMake(20 + threeImageCellWidth, 36, threeImageCellWidth, threeImageCellWidth*5/8)];
        _midleImage.contentMode = UIViewContentModeScaleAspectFill;
        _midleImage.layer.masksToBounds = YES;
        [self addSubview:_midleImage];
        
        _rightImage = [[UIImageView alloc] initWithFrame:CGRectMake(24 + threeImageCellWidth*2, 36, threeImageCellWidth, threeImageCellWidth*5/8)];
        _rightImage.contentMode = UIViewContentModeScaleAspectFill;
        _rightImage.layer.masksToBounds = YES;
        [self addSubview:_rightImage];
        
        _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 36 + threeImageCellWidth*5/8, MainScreenWidth - 30, 20)];
        _timeLabel.textColor = HEXCOLOR(0x666666);
        _timeLabel.font = [UIFont systemFontOfSize:12];
        _timeLabel.backgroundColor = [UIColor clearColor];
        [self addSubview:_timeLabel];
        
        _tagsLabel = [[UILabel alloc] initWithFrame:CGRectMake(MainScreenWidth - 112, 36 + threeImageCellWidth*5/8, 0, 20)];
        _tagsLabel.textColor = HEXCOLOR(0xFFFFFF);
        _tagsLabel.font = [UIFont systemFontOfSize:12];
        _tagsLabel.textAlignment = NSTextAlignmentCenter;
        _tagsLabel.backgroundColor = HEXCOLOR(0x195AC9);
        _tagsLabel.layer.masksToBounds = YES;
        _tagsLabel.layer.cornerRadius = 4.0;
        [self addSubview:_tagsLabel];
    }
    return self;
}
- (void)reSetTagFrame {
    CGRect frame = _tagsLabel.frame;
    
    CGRect rect = [self calculateSizeWithFont:8 Text:_tagsLabel.text];
    
    NSLog(@"%@",NSStringFromCGRect(rect));
    
    frame.size.width = rect.size.width + 10;
    frame.origin.x = MainScreenWidth - frame.size.width - 22;
    
    [_tagsLabel setFrame:frame];
}
-(CGRect)calculateSizeWithFont:(NSInteger)Font Text:(NSString *)Text{
    NSDictionary *attr = @{NSFontAttributeName : [UIFont systemFontOfSize:Font]};
    CGRect rect = [Text boundingRectWithSize:CGSizeMake(MAXFLOAT, 16)
                                     options:NSStringDrawingUsesFontLeading|NSStringDrawingUsesLineFragmentOrigin
                                  attributes:attr
                                     context:nil];
    return rect;
}

@end