NewsVoiceTableViewCell.m 2.94 KB
//
//  NewsVoiceTableViewCell.m
//  SCIOLiveCN
//
//  Created by huayu on 16/12/9.
//  Copyright © 2016年 huayu. All rights reserved.
//

#import "NewsVoiceTableViewCell.h"

@implementation NewsVoiceTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = [UIColor whiteColor];
        _bgView.layer.masksToBounds = YES;
        _bgView.layer.cornerRadius = 6.0;
        [self.contentView addSubview:_bgView];
        
        _titleLabel=[[UILabel alloc]init];
        [_titleLabel sizeToFit];
        _titleLabel.numberOfLines = 0;
        _titleLabel.textColor = HEXCOLOR(0x333333);
        _titleLabel.font = [UIFont systemFontOfSize:16];
        [_bgView addSubview:_titleLabel];
        
        _timeLabel = [[UILabel alloc] init];
        [_timeLabel sizeToFit];
        _timeLabel.backgroundColor = [UIColor clearColor];
        _timeLabel.textColor = HEXCOLOR(0x666666);
        _timeLabel.font = [UIFont systemFontOfSize:12];
        [_bgView addSubview:_timeLabel];
        
        {
            [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(@5);
                make.left.equalTo(@12);
                make.bottom.equalTo(@-5);
                make.right.equalTo(@-12);
            }];
            
            [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self->_bgView.mas_top).with.offset(10);
                make.left.equalTo(self->_bgView.mas_left).with.offset(10);
                make.right.equalTo(self->_bgView.mas_right).with.offset(-10);
                
            }];
            
            [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self->_titleLabel.mas_bottom).with.offset(2);
                make.left.mas_equalTo(self->_titleLabel);
                make.bottom.mas_equalTo(self->_bgView.mas_bottom).with.offset(-10);
            }];
        }
    }
    return self;
}

- (void)reSetTagFrame {
    CGRect frame = _tagLabel.frame;
    [_tagLabel sizeToFit];
    
    CGRect rect = [self calculateSizeWithFont:12 Text:_tagLabel.text];
    frame.size.width = rect.size.width + 10;
    frame.origin.x = MainScreenWidth - frame.size.width - 24 - 40 - 5;
    [_tagLabel 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