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

#import "BigImageTableViewCell.h"

@implementation BigImageTableViewCell
- (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, cellItemWidth*5/8 + 66.0)];
        _backGroundView.backgroundColor = [UIColor whiteColor];
        [self addSubview:_backGroundView];
        
        _bigImage = [[UIImageView alloc] initWithFrame:CGRectMake(12, 6, MainScreenWidth - 24, cellItemWidth*5/8)];
        _bigImage.contentMode = UIViewContentModeScaleAspectFill;
        _bigImage.layer.masksToBounds = YES;
        [self addSubview:_bigImage];
        
        _playImage = [[UIImageView alloc] initWithFrame:CGRectMake(12 + (MainScreenWidth - 24 - 50)/2, 6 + (cellItemWidth*5/8 - 50)/2, 50, 50)];
        [self addSubview:_playImage];
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, cellItemWidth*5/8 + 10, MainScreenWidth - 40, 40)];
        _titleLabel.numberOfLines = 2;
        _titleLabel.backgroundColor = [UIColor clearColor];
        _titleLabel.textColor = HEXCOLOR(0x333333);
        _titleLabel.font = [UIFont systemFontOfSize:16];
        [self addSubview:_titleLabel];
        
        _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, cellItemWidth*5/8 + 50, MainScreenWidth - 40, 16)];
        _timeLabel.backgroundColor = [UIColor clearColor];
        _timeLabel.textColor = HEXCOLOR(0x666666);
        _timeLabel.font = [UIFont systemFontOfSize:12];
        [self addSubview:_timeLabel];
        
        _tagsLabel = [[UILabel alloc] initWithFrame:CGRectMake(MainScreenWidth - 112, cellItemWidth*5/8 + 50, 0, 16)];
        _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;
    [_tagsLabel sizeToFit];
    
    CGRect rect = [self calculateSizeWithFont:12 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