CNLiveSearchListCell.m
2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// 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