CNMessgeNoteCell.m
2.34 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
//
// CNMeaageNoteCell.m
// CNLiveCMineModule
//
// Created by iOS on 2022/12/7.
//
#import "CNMessgeNoteCell.h"
@interface CNMessgeNoteCell ()
@property (nonatomic, strong)UIView *bgView;
@property (nonatomic, strong)UILabel *titleLabel;
@property (nonatomic, strong)UISwitch *switchBtn;
@end
@implementation CNMessgeNoteCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.contentView.backgroundColor = [UIColor clearColor];
self.backgroundColor = UIColorClear;
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self.contentView addSubview:self.bgView];
[self.bgView addSubview:self.titleLabel];
[self.bgView addSubview:self.switchBtn];
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.equalTo(self);
make.top.equalTo(self).offset(10);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.bgView);
make.left.equalTo(self).offset(16);
}];
[self.switchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.bgView);
make.right.equalTo(self).offset(-8);
}];
}
return self;
}
- (void)switchValueChanged:(UISwitch *)sender{
self.model.state = sender.isOn;
if (self.changeSwitchBlock) {
self.changeSwitchBlock(self.model);
}
}
#pragma mark - Setting
- (void)setModel:(CNMessageNoteModel *)model{
_model = model;
self.titleLabel.text = model.title;
[self.switchBtn setOn:model.state];
}
#pragma mark - Getting
- (UIView *)bgView{
if (!_bgView) {
_bgView = [[UIView alloc] init];
_bgView.backgroundColor = UIColorWhite;
}
return _bgView;
}
- (UILabel *)titleLabel{
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.textColor = UIColorHex(#282828);
_titleLabel.font = UIFontMake(16);
}
return _titleLabel;
}
- (UISwitch *)switchBtn{
if (!_switchBtn) {
_switchBtn = [[UISwitch alloc] init];
[_switchBtn addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
}
return _switchBtn;
}
@end