CNLiveServiceOrLookCell.m 4.22 KB
//
//  CNLiveServiceOrLookCell.m
//  CNLiveCServiceModule
//
//  Created by CNLive on 2021/11/30.
//

#import "CNLiveServiceOrLookCell.h"
@interface CNLiveServiceOrLookCell()
@property (nonatomic, strong) UIImageView *logoImage;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) QMUIButton *rightBtn;
@end

@implementation CNLiveServiceOrLookCell
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self.contentView addSubview:self.logoImage];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.rightBtn];
        [self makeSubViewsLayout];
    }
    return self;
}
- (void)makeSubViewsLayout{
    [self.logoImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(10);
        make.centerY.equalTo(self.contentView);
        make.height.width.offset(30);
    }];
    [self.rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-10);
        make.centerY.equalTo(self.logoImage);
        make.width.offset(45);
        make.height.offset(18);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.logoImage.mas_right).offset(10);
        make.centerY.equalTo(self.logoImage);
        make.right.equalTo(self.rightBtn.mas_left).offset(-10);
    }];
}
#pragma mark - Setting&&getting
- (void)setModel:(CnLivePageContentModel *)model
{
    _titleLabel.font = UIFontCNMake(10);
    _model = model;
    [self.logoImage sd_setImageWithURL:[NSURL URLWithString:model.poster]];
    NSMutableAttributedString *string = nil;
    if (model.subTitle && [model.subTitle isKindOfClass:[NSString class]]) {
        string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@  %@",model.title,model.subTitle]];
    }else{
        string = [[NSMutableAttributedString alloc] initWithString:model.title];
    }
    
    [string addAttribute:NSFontAttributeName value:UIFontCNMake(13) range:NSMakeRange(0, model.title.length)];
    [string addAttribute:NSForegroundColorAttributeName value:CNLiveColorWithHexString(@"#333333") range:NSMakeRange(0, model.title.length)];
    self.titleLabel.attributedText =string;
}
- (void)setType:(CNLiveCellShowType)type
{
    _type = type;
    if (type == CNLiveCellShowTypeService) {
        [self.rightBtn setImage:[UIImage loadCServiceBundle:@"service_right"] forState:UIControlStateNormal];
        [self.rightBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-10);
            make.centerY.equalTo(self.logoImage);
            make.width.offset(18);
            make.height.offset(18);
        }];
    }else{
        self.rightBtn.layer.cornerRadius = 9;
        [self.rightBtn setTitle:@"进入 " forState:UIControlStateNormal];
        [self.rightBtn setImage:[UIImage loadCServiceBundle:@"service_enter"] forState:UIControlStateNormal];
        self.rightBtn.backgroundColor = CNLiveColorWithHexString(@"#2C7EEE");
        [self.rightBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-10);
            make.centerY.equalTo(self.logoImage);
            make.width.offset(45);
            make.height.offset(18);
        }];
    }
}
- (UIImageView *)logoImage{
    if (!_logoImage) {
        _logoImage = [[UIImageView alloc] init];
        _logoImage.clipsToBounds = YES;
        _logoImage.layer.cornerRadius = 15;
    }
    return _logoImage;
}
- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = UIFontCNMake(10);
        _titleLabel.textColor = CNLiveColorWithHexString(@"#999999");
        _titleLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _titleLabel;
}
- (QMUIButton *)rightBtn
{
    if (!_rightBtn) {
        _rightBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
        _rightBtn.userInteractionEnabled = NO;
        _rightBtn.titleLabel.font = UIFontCNMake(10);
        _rightBtn.imagePosition = QMUIButtonImagePositionRight;
        [_rightBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
    }
    return _rightBtn;
}
@end