CNWitnessSearchPersonCell.m
6.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//
// CNWitnessSearchPersonCell.m
// CNLiveVideoClassifyKit
//
// Created by CNLive on 2022/6/17.
//
#import "CNWitnessSearchPersonCell.h"
#import "CNWitnessSearchModel.h"
#import "CNWitnessSearchPresent.h"
@interface CNWitnessSearchPersonCell ()
@property (nonatomic, strong)UIImageView *logoImage;
@property (nonatomic, strong)UILabel *nameLabel;
@property (nonatomic, strong)UILabel *fansNumLabel;
@property (nonatomic, strong)QMUIButton *focusedBtn;
@property (nonatomic, strong)UIView *lineView;
@end
@implementation CNWitnessSearchPersonCell
- (instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
[self.contentView addSubview:self.logoImage];
[self.contentView addSubview:self.nameLabel];
[self.contentView addSubview:self.fansNumLabel];
[self.contentView addSubview:self.focusedBtn];
[self.contentView addSubview:self.lineView];
[self.logoImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self);
make.centerY.equalTo(self);
make.width.height.mas_equalTo(50);
}];
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.logoImage).offset(4);
make.left.equalTo(self.logoImage.mas_right).offset(15);
make.right.equalTo(self.focusedBtn.mas_left).offset(-5);
}];
[self.fansNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.nameLabel.mas_bottom).offset(5);
make.left.equalTo(self.logoImage.mas_right).offset(15);
}];
[self.focusedBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self).offset(-3);
make.centerY.equalTo(self);
make.width.mas_equalTo(70);
make.height.mas_equalTo(26);
}];
[self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.bottom.right.equalTo(self);
make.height.mas_equalTo(0.5);
}];
}
return self;
}
- (void)focusedBtnClick:(QMUIButton *)sender{
if (![CNUserShareManager isLogin]) {
#pragma mark -- TODO grp
[CNLiveClassifyJumpBridge showLoginViewWithString:@""];
return;
}
weakself
[QMUITips showLoadingInView:self.contentView];
[CNWitnessSearchPresent requestContentGetContentHeaderFocusType:!sender.selected ToSid:_model.id responseBlock:^(BOOL succeed) {
[QMUITips hideAllTips];
if (succeed) {
if (sender.selected) {
sender.selected = NO;
weakSelf.model.fansNum --;
self.focusedBtn.layer.borderWidth = 0;
}else{
sender.selected = YES;
weakSelf.model.fansNum ++;
self.focusedBtn.layer.borderWidth = 0.5;
}
weakSelf.model.focused = sender.selected;
weakSelf.fansNumLabel.text = [NSString stringWithFormat:@"粉丝%ld",weakSelf.model.fansNum];
}
}];
}
#pragma mark - Setting
- (void)setModel:(CNPersonMessageModel *)model
{
_model = model;
[self.logoImage sd_setImageWithURL:[NSURL URLWithString:model.face] placeholderImage:[UIImage loadBundleImage:@"default _icon_bg"]];
self.nameLabel.text = model.name;
self.fansNumLabel.text = [NSString stringWithFormat:@"粉丝%ld",model.fansNum];
self.focusedBtn.selected = model.focused;
if (model.focused) {
self.focusedBtn.layer.borderWidth = 0.5;
}else{
self.focusedBtn.layer.borderWidth = 0;
}
self.focusedBtn.hidden = [CNUserShareModelUid isEqualToString:model.id];
}
#pragma mark - Getting
- (UIImageView *)logoImage
{
if (!_logoImage) {
_logoImage = [[UIImageView alloc] init];
_logoImage.contentMode = UIViewContentModeScaleAspectFill;
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 50, 50) cornerRadius:25];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.path = path.CGPath;
_logoImage.layer.mask = maskLayer;
_logoImage.userInteractionEnabled = YES;
weakself
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) {
if (weakSelf.selectPersonBlock) {
weakSelf.selectPersonBlock([weakSelf.model mj_keyValues]);
}
}];
[_logoImage addGestureRecognizer:tap];
}
return _logoImage;
}
- (UILabel *)nameLabel
{
if (!_nameLabel) {
_nameLabel = [[UILabel alloc] init];
_nameLabel.textColor = UIColorHex(#333333);
_nameLabel.font = UIFontMake(15);
_nameLabel.textAlignment = NSTextAlignmentLeft;
}
return _nameLabel;
}
- (UILabel *)fansNumLabel
{
if (!_fansNumLabel) {
_fansNumLabel = [[UILabel alloc] init];
_fansNumLabel.textColor = UIColorHex(#999999);
_fansNumLabel.font = UIFontMake(12);
_fansNumLabel.textAlignment = NSTextAlignmentLeft;
}
return _fansNumLabel;
}
- (QMUIButton *)focusedBtn
{
if (!_focusedBtn) {
_focusedBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
[_focusedBtn setTitle:@"+ 关注" forState:UIControlStateNormal];
[_focusedBtn setTitleColor:UIColorWhite forState:UIControlStateNormal];
[_focusedBtn setBackgroundImage:[UIImage imageWithColor:UIColorHex(#F5A623)] forState:UIControlStateNormal];
[_focusedBtn setTitle:@"已关注" forState:UIControlStateSelected];
[_focusedBtn setTitleColor:UIColorHex(#999999) forState:UIControlStateSelected];
[_focusedBtn setBackgroundImage:[UIImage imageWithColor:UIColorWhite] forState:UIControlStateSelected];
_focusedBtn.titleLabel.font = UIFontMake(13);
_focusedBtn.spacingBetweenImageAndTitle = 5;
_focusedBtn.layer.cornerRadius = 14.5;
_focusedBtn.clipsToBounds = YES;
// _likeBtn.touchAreaInsets = UIEdgeInsetsMake(-5, -5, -5, -5);
[_focusedBtn addTarget:self action:@selector(focusedBtnClick:) forControlEvents:UIControlEventTouchUpInside];
}
return _focusedBtn;
}
- (UIView *)lineView{
if (!_lineView) {
_lineView = [[UIView alloc] init];
_lineView.backgroundColor = UIColorHex(#F2F2F2);
}
return _lineView;
}
@end