CNLiveServiceOrLookCell.m
4.22 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//
// 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