CNLIveCategoryCell.m 2.9 KB
//
//  CNLIveCategoryCell.m
//  CNLiveCServiceModule
//
//  Created by CNLive on 2021/12/1.
//

#import "CNLIveCategoryCell.h"

@interface CNLIveCategoryCell()
@property (nonatomic, strong) UIImageView *logoView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *subTitle;
@property (nonatomic, strong) UIImageView *rightImage;
@end

@implementation CNLIveCategoryCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self.contentView addSubview:self.logoView];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.subTitle];
        [self.contentView addSubview:self.rightImage];
    }
    return self;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    [self.logoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(15);
        make.centerY.equalTo(self.contentView);
        make.height.width.offset(40);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.logoView.mas_right).offset(12.5);
        make.bottom.equalTo(self.logoView.mas_centerY).offset(-2);
        make.right.equalTo(self.contentView);
    }];
    [self.rightImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-15);
        make.width.height.offset(18);
        make.centerY.equalTo(self);
    }];
    [self.subTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel);
        make.top.equalTo(self.logoView.mas_centerY).offset(2);
        make.right.equalTo(self.rightImage.mas_left).offset(-5);
    }];
   
}

#pragma mark - Setting&&Getting
- (void)setModel:(CNLiveSearchModel *)model
{
    _model = model;
    [self.logoView sd_setImageWithURL:[NSURL URLWithString:model.icon]];
    self.titleLabel.text = model.title;
    self.subTitle.text = model.desc;
    [self layoutSubviews];
}
- (UIImageView *)logoView{
    if (!_logoView) {
        _logoView = [[UIImageView alloc] init];
        _logoView.clipsToBounds = YES;
        _logoView.layer.cornerRadius = 22.5;
    }
    return _logoView;
}

- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = UIFontMake(15);
        _titleLabel.textColor = CNLiveColorWithHexString(@"#666666");
        _titleLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _titleLabel;
}

- (UILabel *)subTitle
{
    if (!_subTitle) {
        _subTitle = [[UILabel alloc] init];
        _subTitle.textColor = CNLiveColorWithHexString(@"#A9A9A9");
        _subTitle.font = UIFontMake(12);
    }
    return _subTitle;
}

- (UIImageView *)rightImage
{
    if (!_rightImage) {
        _rightImage = [[UIImageView alloc] init];
        [_rightImage setImage:[UIImage loadCServiceBundle:@"service_right"]];
    }
    return _rightImage;
}
@end