MajorCommentCell.m
3.5 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
//
// MajorCommentCell.m
// DreamSleep
//
// Created by peter on 2022/10/9.
//
#import "MajorCommentCell.h"
@interface MajorCommentCell ()
@property (nonatomic, strong) UIImageView *userIcon;
@property (nonatomic, strong) UILabel *userNameLab;
@property (nonatomic, strong) UILabel *timeLab;
@property (nonatomic, strong) UILabel *commentContentLab;
@end
@implementation MajorCommentCell
- (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.userIcon mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(30);
make.top.equalTo(self.contentView).offset(15);
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)setCommentModel:(CommentModel *)commentModel {
_commentModel = commentModel;
[self.userIcon yy_setImageWithURL:[NSURL URLWithString:commentModel.user_profile] placeholder:[UIImage defaultPlaceholderWithSize:CGSizeMake(40, 40)]];
self.userNameLab.text = commentModel.nick_name;
self.timeLab.text = commentModel.publish_time;
self.commentContentLab.text = commentModel.content;
[self.commentContentLab mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.userIcon.mas_bottom).offset(12);
make.left.equalTo(self.contentView).offset(kContentMargin);
make.right.equalTo(self.contentView).offset(-kContentMargin);
make.height.equalTo(@([commentModel commentContentHeight]));
}];
}
#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:[CommentModel commentContentFont]];
_commentContentLab.dk_textColorPicker = DKColorPickerWithColors(MainTextColor, ColorFromHexA(0xFFFFFF, .5), DSWhite);
_commentContentLab.numberOfLines = 0;
}
return _commentContentLab;
}
@end