MessageOfficialNotiCell.m
3.4 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
//
// MessageOfficialNotiCell.m
// DreamSleep
//
// Created by peter on 2022/10/10.
//
#import "MessageOfficialNotiCell.h"
@interface MessageOfficialNotiCell ()
@property (nonatomic, strong) UIImageView *icon;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *detailLab;
@property (nonatomic, strong) UILabel *mesCountLab;
@end
@implementation MessageOfficialNotiCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.backgroundColor = DSClearColor;
[self.contentView addSubview:self.icon];
[self.contentView addSubview:self.titleLab];
[self.contentView addSubview:self.detailLab];
[self.contentView addSubview:self.mesCountLab];
[self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(15);
make.top.equalTo(self.contentView).offset(18);
make.size.mas_equalTo(CGSizeMake(40, 40));
}];
[self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.icon.mas_right).offset(12);
make.top.equalTo(self.icon);
make.right.equalTo(self.contentView).offset(-50);
}];
[self.detailLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.titleLab);
make.bottom.equalTo(self.icon);
make.right.equalTo(self.titleLab);
}];
[self.mesCountLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.contentView);
make.right.equalTo(self.contentView).offset(-15);
make.size.mas_equalTo(CGSizeMake(20, 20));
}];
}
return self;
}
- (void)setOfficialModel:(MessageOfficialModel *)officialModel {
_officialModel = officialModel;
[self.icon yy_setImageWithURL:[NSURL URLWithString:officialModel.iconName] placeholder:[UIImage defaultPlaceholderWithSize:CGSizeMake(40, 40)]];
self.titleLab.text = officialModel.title;
self.mesCountLab.hidden = !officialModel.messageCount;
self.mesCountLab.text = [NSString stringWithFormat:@"%d", officialModel.messageCount];
self.detailLab.text = self.mesCountLab.hidden == NO ? officialModel.detail : (officialModel.isPraise ? @"暂无点赞" : @"暂无通知");
}
#pragma mark - lazy
- (UIImageView *)icon {
if (!_icon) {
_icon = [UIImageView new];
_icon.dk_alphaPicker = DKAlphaPickerWithAlphas(1, .5, .5);
[_icon cornerRadius:20];
}
return _icon;
}
- (UILabel *)titleLab {
if (!_titleLab) {
_titleLab = [UILabel labWithFont:BoldFont(15)];
_titleLab.dk_textColorPicker = DKColorPickerWithKey(Dk_TITLE);
}
return _titleLab;
}
- (UILabel *)detailLab {
if (!_detailLab) {
_detailLab = [UILabel labWithFont:SysFont(14)];
_detailLab.dk_textColorPicker = DKColorPickerWithColors(SubTitleColor, ColorFromHexA(0xFFFFFF, .5), DSWhite);
}
return _detailLab;
}
- (UILabel *)mesCountLab {
if (!_mesCountLab) {
_mesCountLab = [UILabel labWithTextColor:DSWhite font:SysFont(12)];
_mesCountLab.backgroundColor = ColorFromHex(0xF04B77);
_mesCountLab.textAlignment = NSTextAlignmentCenter;
[_mesCountLab cornerRadius:10];
}
return _mesCountLab;
}
@end