CNLiveSearchListCell.m 2.73 KB
//
//  CNLiveSearchListCell.m
//  CNLiveCServiceModule
//
//  Created by CNLive on 2021/11/25.
//

#import "CNLiveSearchListCell.h"

@interface CNLiveSearchListCell()
@property (nonatomic, strong) UIImageView *logoView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIView *line;
@end

@implementation CNLiveSearchListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.logoView];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.line];
    }
    return self;
}
- (void)layoutSubviews
{
    [self.logoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.contentView).offset(15);
        make.height.width.offset(45);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.logoView.mas_right).offset(15);
        make.centerY.equalTo(self.logoView);
    }];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(0.5);
        make.bottom.equalTo(self.contentView);
        make.left.equalTo(self.titleLabel);
        make.right.equalTo(self.contentView).offset(-15);
    }];
}
#pragma mark - Setting&&Getting
- (void)setModel:(CNLiveSearchModel *)model
{
    _model = model;
    [self.logoView sd_setImageWithURL:[NSURL URLWithString:model.icon]];
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:model.title];
    NSRange range = [model.title rangeOfString:model.searchStr];
    UIColor *color = CNLiveColorWithHexString(@"#00CD1E");
    [attrString addAttribute:NSFontAttributeName value:UIFontMake(14) range:NSMakeRange(0, model.title.length)];
    [attrString addAttribute:NSForegroundColorAttributeName value:CNLiveColorWithHexString(@"#333333") range:NSMakeRange(0, model.title.length)];
    [attrString addAttribute:NSForegroundColorAttributeName value:color range:range];
    self.titleLabel.attributedText = attrString;
    [self.titleLabel sizeToFit];
    [self setNeedsLayout];
}
- (UIImageView *)logoView{
    if (!_logoView) {
        _logoView = [[UIImageView alloc] init];
        _logoView.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _logoView;
}

- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
    }
    return _titleLabel;
}
- (UIView *)line
{
    if (!_line) {
        _line = [[UIView alloc] init];
        _line.backgroundColor = CNLiveColorWithHexString(@"#F2F2F2");
    }
    return _line;
}
@end