CNLiveTableViewCell.m 4.37 KB
//
//  CNLiveTableViewCell.m
//  CNLiveScioLive
//
//  Created by CNLive-zxw on 2018/9/18.
//  Copyright © 2018年 CNLive. All rights reserved.
//

#import "CNLiveTableViewCell.h"
#import "CNLiveModel.h"

@interface CNLiveTableViewCell()
@property (nonatomic, strong) UIImageView *backgroundImage;//背景图
@property (nonatomic, strong) UIImageView *picImage;//一张图片 三张图中间一张
@property (nonatomic, strong) UIImageView *playImage;//播放

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *timeLabel;

@end

@implementation CNLiveTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = HEXCOLOR(0xebebeb);
        
        _backgroundImage = [[UIImageView alloc] init];
        _backgroundImage.contentMode = UIViewContentModeCenter;
        _backgroundImage.layer.masksToBounds = YES;
        _backgroundImage.layer.cornerRadius = 2.0;
        _backgroundImage.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_backgroundImage];
        
        _picImage = [[UIImageView alloc] init];
        _picImage.contentMode = UIViewContentModeScaleAspectFill;
        _picImage.layer.masksToBounds = YES;
        _picImage.image = [UIImage imageNamed:@"placeholder"];
        [self.contentView addSubview:_picImage];
        
        _playImage = [[UIImageView alloc] init];
        _playImage.layer.masksToBounds = YES;
        _playImage.image = [UIImage imageNamed:@"cnlive_play"];
        [self.contentView addSubview:_playImage];
        
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.numberOfLines = 2;
        _titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
        _titleLabel.textColor = HEXCOLOR(0x333333);
        _titleLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_titleLabel];
        
        _timeLabel = [[UILabel alloc] init];
        _timeLabel.numberOfLines = 1;
        _timeLabel.textColor = HEXCOLOR(0xbbbbbb);
        _timeLabel.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:_timeLabel];
        
    }
    return self;
    
}
- (void)setModel:(CNLiveModel *)model{
    _model = model;
    _titleLabel.text = model.title;
    _timeLabel.text = model.createDate;
    [_picImage sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    [self layoutSubviews];
    
}
- (void)layoutSubviews{
    [_backgroundImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(0);
        make.right.equalTo(self.mas_right).with.offset(0);
        make.top.equalTo(self.mas_top).with.offset(5);
        make.bottom.equalTo(self.mas_bottom).with.offset(-5);
    }];
    
    [_picImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_backgroundImage.mas_left).with.offset(10);
        make.top.equalTo(self->_backgroundImage.mas_top).with.offset(5);
        make.width.offset(80*MainScale*16/9.0);
        make.bottom.equalTo(self->_backgroundImage.mas_bottom).with.offset(-5);
        
    }];
    
    [_playImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_picImage.mas_left).with.offset((80*MainScale*16/9.0-30)/2.0);
        make.centerY.offset(self->_picImage.centerY);
        make.width.offset(30);
        make.height.offset(30);
        
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_picImage.mas_right).with.offset(10);
        make.top.equalTo(self->_backgroundImage.mas_top).with.offset(5);
        make.right.equalTo(self->_backgroundImage.mas_right).with.offset(-5);
        
    }];
    
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_picImage.mas_right).with.offset(10);
        make.right.equalTo(self->_backgroundImage.mas_right).with.offset(-5);
        make.bottom.equalTo(self->_backgroundImage.mas_bottom).with.offset(-5);
    }];
    
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end