DynamicCommentCell.m
6.8 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
163
//
// DynamicCommentCell.m
// DreamSleep
//
// Created by peter on 2022/10/8.
//
#import "DynamicCommentCell.h"
@interface DynamicCommentCell ()
@property (nonatomic, strong) UIImageView *userIcon;
@property (nonatomic, strong) UILabel *userNameLab;
@property (nonatomic, strong) UILabel *timeLab;
@property (nonatomic, strong) UILabel *commentContentLab;
@property (nonatomic, strong) UIView *replyView;
@property (nonatomic, strong) UILabel *replyUserLab;
@property (nonatomic, strong) UILabel *replyContentLab;
@property (nonatomic, strong) UIButton *totalReplyBtn;
@end
@implementation DynamicCommentCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.dk_backgroundColorPicker = DKColorPickerWithColors(DSWhite, DarkColor, DSWhite);
[self.contentView addSubview:self.userIcon];
[self.contentView addSubview:self.userNameLab];
[self.contentView addSubview:self.timeLab];
[self.contentView addSubview:self.commentContentLab];
[self.contentView addSubview:self.replyView];
[self.userIcon mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(30);
make.top.equalTo(self.contentView);
make.size.mas_equalTo(CGSizeMake(40, 40));
}];
[self.userNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.userIcon.mas_right).offset(14);
make.top.equalTo(self.userIcon);
make.right.equalTo(self.contentView).offset(-30);
}];
[self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.userNameLab);
make.bottom.equalTo(self.userIcon);
}];
}
return self;
}
- (void)setComReplyModel:(ComReplyModel *)comReplyModel {
_comReplyModel = comReplyModel;
[self.userIcon yy_setImageWithURL:[NSURL URLWithString:comReplyModel.commentModel.user_profile] placeholder:[UIImage defaultPlaceholderWithSize:CGSizeMake(40, 40)]];
self.userNameLab.text = comReplyModel.commentModel.nick_name;
self.timeLab.text = comReplyModel.commentModel.publish_time;
self.commentContentLab.text = comReplyModel.commentModel.content;
self.replyUserLab.text = [comReplyModel replyNickName];
self.replyContentLab.attributedText = [comReplyModel replyContentAttriStr];
[self.totalReplyBtn setTitle:[NSString stringWithFormat:@"共%d条回复>", comReplyModel.commentModel.total_replys] forState:UIControlStateNormal];
self.totalReplyBtn.hidden = comReplyModel.commentModel.total_replys > 1 ? NO : YES;
[self.commentContentLab mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.userIcon.mas_bottom).offset(8);
make.left.equalTo(self.contentView).offset([comReplyModel commentContentLeftMargin]);
make.right.equalTo(self.contentView).offset(-[comReplyModel commentContentRightMargin]);
make.height.equalTo(@([comReplyModel commentContentHeight]));
}];
[self.replyView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.commentContentLab.mas_bottom).offset(12);
make.left.right.equalTo(self.commentContentLab);
make.height.equalTo(@([comReplyModel replyViewHeight]));
}];
[self.replyUserLab mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.replyView).offset(8);
make.left.equalTo(self.replyView).offset(8);
make.width.equalTo(@([comReplyModel replyNickNameW]));
}];
[self.replyContentLab mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.replyUserLab);
make.left.equalTo(self.replyUserLab.mas_right);
make.size.mas_equalTo([comReplyModel replyContentSize]);
}];
[self.totalReplyBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.replyUserLab);
make.bottom.equalTo(self.replyView).offset(-8);
}];
}
#pragma mark - private
- (void)lookAllRelpyList {
if (self.lookAllRelpyListBlock) {
self.lookAllRelpyListBlock();
}
}
#pragma mark - lazy
- (UIImageView *)userIcon {
if (!_userIcon) {
_userIcon = [UIImageView new];
[_userIcon cornerRadius:20];
_userIcon.dk_alphaPicker = DKAlphaPickerWithAlphas(1.f, 0.5f, 0.1f);
}
return _userIcon;
}
- (UILabel *)userNameLab {
if (!_userNameLab) {
_userNameLab = [UILabel labWithFont:BoldFont(15)];
_userNameLab.dk_textColorPicker = DKColorPickerWithColors(MainTextColor, DkTitleColor, DSWhite);
}
return _userNameLab;
}
- (UILabel *)timeLab {
if (!_timeLab) {
_timeLab = [UILabel labWithFont:SysFont(12)];
_timeLab.dk_textColorPicker = DKColorPickerWithColors(SmallTextColor, ColorFromHexA(0xFFFFFF, .3), DSWhite);
}
return _timeLab;
}
- (UILabel *)commentContentLab {
if (!_commentContentLab) {
_commentContentLab = [UILabel labWithFont:[ComReplyModel commentContentFont]];
_commentContentLab.dk_textColorPicker = DKColorPickerWithColors(MainTextColor, ColorFromHexA(0xFFFFFF, .5), DSWhite);
_commentContentLab.numberOfLines = 0;
_commentContentLab.userInteractionEnabled = YES;
}
return _commentContentLab;
}
- (UIView *)replyView {
if (!_replyView) {
_replyView = [UIView new];
[_replyView cornerRadius:12];
_replyView.dk_backgroundColorPicker = DKColorPickerWithColors(BGColor, CornerViewDarkColor, BGColor);
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lookAllRelpyList)];
[_replyView addGestureRecognizer:tapGR];
UILabel *replyUserLab = [UILabel labWithFont:[ComReplyModel replyNickNameFont]];
replyUserLab.dk_textColorPicker = DKColorPickerWithColors(SubTitleColor, DkTitleColor, DSWhite);
[_replyView addSubview:replyUserLab];
self.replyUserLab = replyUserLab;
UILabel *replyContentLab = [UILabel labWithFont:[ComReplyModel replyContentFont]];
replyContentLab.numberOfLines = 0;
replyContentLab.dk_textColorPicker = DKColorPickerWithColors(MainTextColor, ColorFromHexA(0xFFFFFF, .5), DSWhite);
[_replyView addSubview:replyContentLab];
self.replyContentLab = replyContentLab;
UIButton *totalReplyBtn = [UIButton btnWithTitle:@"" font:SysFont(15)];
[totalReplyBtn setTitleColor:BrandColor forState:UIControlStateNormal];
totalReplyBtn.userInteractionEnabled = NO;
[_replyView addSubview:totalReplyBtn];
self.totalReplyBtn = totalReplyBtn;
}
return _replyView;
}
@end