SafeSleepCell.m
4.6 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
//
// SafeSleepCell.m
// DreamSleep
//
// Created by peter on 2022/4/11.
//
#import "SafeSleepCell.h"
#import "SafeHelperCollectionView.h"
#import "SafeHelperCollectionViewCell.h"
@interface SafeSleepCell ()
@property (nonatomic, strong) UIView *leftIV;
@property (nonatomic, strong) UILabel *recommandLb;
@property (nonatomic, strong) UIButton *moreBtn;
@property (nonatomic, strong) UIButton *timerBtn;
@property (nonatomic, strong) SafeHelperCollectionView *shCollectionView;
@end
@implementation SafeSleepCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.contentView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
[self.contentView addSubview:self.leftIV];
[self.contentView addSubview:self.recommandLb];
}
return self;
}
// 隐藏选中Cell时的分割线
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
self.selectedBackgroundView = [[UIView alloc] initWithFrame:self.frame];
self.selectedBackgroundView.backgroundColor = DSClearColor;
[super setSelected:selected animated:animated];
}
- (void)configureCellWithModel:(SafeSleepModel *)model indexPath:(NSIndexPath *)indexPath {
_model = model;
_indexPath = indexPath;
self.recommandLb.text = model.title;
[self.leftIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView.mas_left).offset(10);
make.top.equalTo(self.contentView.mas_top).offset(33);
make.width.equalTo(@4);
make.height.equalTo(@16);
}];
[self.recommandLb mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.leftIV.mas_right).offset(10);
make.centerY.equalTo(self.leftIV.mas_centerY);
}];
if (indexPath.row == 2) { // 好眠声音区域
[self.contentView addSubview:self.timerBtn];
[self.timerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.contentView.mas_right).offset(-5);
make.width.equalTo(@100);
make.height.equalTo(@30);
make.centerY.equalTo(self.leftIV.mas_centerY);
}];
} else { // 舒眠课程和助眠音乐
[self.contentView addSubview:self.moreBtn];
[self.contentView addSubview:self.shCollectionView];
[self.moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.contentView.mas_right).offset(-5);
make.width.equalTo(@100);
make.height.equalTo(@30);
make.centerY.equalTo(self.leftIV.mas_centerY);
}];
[self.shCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.recommandLb.mas_bottom).offset(17);
make.left.equalTo(self.leftIV);
make.right.equalTo(self.contentView);
make.bottom.equalTo(self.contentView).offset(0);
}];
}
}
- (UIView *)leftIV {
if (!_leftIV) {
_leftIV = [UIView new];
_leftIV.backgroundColor = BrandColor;
_leftIV.layer.cornerRadius = 3;
_leftIV.layer.masksToBounds = YES;
}
return _leftIV;
}
- (UILabel *)recommandLb {
if (!_recommandLb) {
_recommandLb = [UILabel dkLabWithText:@"助眠音乐" font:BoldFont(16.0)];
}
return _recommandLb;
}
- (UIButton *)moreBtn {
if (!_moreBtn) {
_moreBtn = [UIButton dkBtnWithSubTitle:@"查看全部" imgName:@"rightRow" font:SysFont(12)];
_moreBtn.frame = CGRectMake(0, 0, 100, 40);
[_moreBtn adjustLayoutWithType:UIButtonLayoutTypeLeftTitleRightImage midSpace:4 sizeToFit:NO];
[_moreBtn addTarget:self action:@selector(lookMore:) forControlEvents:UIControlEventTouchUpInside];
}
return _moreBtn;
}
- (UIButton *)timerBtn {
if (!_timerBtn) {
_timerBtn = [UIButton new];
[_timerBtn dk_setImage:DKImagePickerWithNames(@"timerIcon", @"timerIcon_dk", @"timerIcon_dk") forState:UIControlStateNormal];
[_timerBtn addTarget:self action:@selector(timerSetting:) forControlEvents:UIControlEventTouchUpInside];
}
return _timerBtn;
}
- (SafeHelperCollectionView *)shCollectionView {
if (!_shCollectionView) {
_shCollectionView = [[SafeHelperCollectionView alloc] initCollectionViewWithIndexPath:self.indexPath];
}
return _shCollectionView;
}
#pragma mark - Actions
- (void)timerSetting:(UIButton *)sender {
DSLog(@"timerSetting");
}
- (void)lookMore:(UIButton *)sender {
DSLog(@"cellIndexPath:%ld", self.indexPath.row);
}
@end