StartReadyView.m
8.3 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
//
// StartReadyView.m
// DreamSleep
//
// Created by peter on 2022/7/13.
//
#import "StartReadyView.h"
#import "ReadyItem.h"
@interface LineView : UIView
@end
@implementation LineView
- (instancetype)initWithFrame:(CGRect)frame {
if (self == [super initWithFrame:frame]) {
UILabel *lineLab = [UILabel labWithText:@"- - - - - - - - - - - - - - - -" font:SysFont(10) fit:YES];
lineLab.lineBreakMode = NSLineBreakByClipping;
lineLab.dk_textColorPicker = DKColorPickerWithColors(BrandColor, SubNaviDarkColor, DSWhite);
[self addSubview:lineLab];
UIView *circle = [UIView new];
circle.layer.borderWidth = 1.0;
circle.layer.dk_borderColorPicker = DKColorPickerWithColors(BrandColor, SubNaviDarkColor, DSWhite);
[circle cornerRadius:3.0];
[self addSubview:circle];
UIView *center = [UIView new];
[center cornerRadius:1.0];
center.dk_backgroundColorPicker = DKColorPickerWithColors(BrandColor, SubNaviDarkColor, DSWhite);
[self addSubview:center];
[lineLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.bottom.equalTo(self);
make.right.equalTo(circle.mas_left);
}];
[circle mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.equalTo(@6.0);
make.top.bottom.right.equalTo(self);
}];
[center mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.equalTo(@2.0);
make.center.equalTo(circle);
}];
}
return self;
}
@end
@interface ItemCell : UIView
@property (nonatomic, strong) ReadyItem *item;
@property (nonatomic, strong) UIImageView *icon;
@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UILabel *timeLab;
@end
@implementation ItemCell
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self addSubview:self.icon];
[self addSubview:self.nameLab];
[self addSubview:self.timeLab];
[self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self);
make.centerX.equalTo(self);
make.width.height.equalTo(@40);
}];
[self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.icon.mas_bottom).offset(16);
make.centerX.equalTo(self);
make.left.equalTo(self).offset(1);
make.right.equalTo(self).offset(-1);
}];
[self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.bottom.equalTo(self);
make.left.equalTo(self).offset(2);
make.right.equalTo(self).offset(-2);
}];
}
return self;
}
- (void)setItem:(ReadyItem *)item {
_item = item;
[self.icon yy_setImageWithURL:[NSURL URLWithString:item.icon] options:YYWebImageOptionShowNetworkActivity];
self.nameLab.text = item.item_name;
self.timeLab.text = [NSString stringWithFormat:@"%dmin", item.time];
}
- (UIImageView *)icon {
if (!_icon) {
_icon = [UIImageView new];
}
return _icon;
}
- (UILabel *)nameLab {
if (!_nameLab) {
_nameLab = [UILabel labWithFont:BoldFont(14.0)];
_nameLab.textAlignment = NSTextAlignmentCenter;
_nameLab.dk_textColorPicker = DKColorPickerWithKey(Dk_TITLE);
}
return _nameLab;
}
- (UILabel *)timeLab {
if (!_timeLab) {
_timeLab = [UILabel labWithFont:SysFont(12.0)];
_timeLab.textAlignment = NSTextAlignmentCenter;
_timeLab.dk_textColorPicker = DKColorPickerWithColors(SubTitleColor, ColorFromHexA(0xFFFFFF, .3), DSWhite);
}
return _timeLab;
}
@end
@interface StartReadyView ()
@property (nonatomic, strong) UIImageView *headIV;
@property (nonatomic, strong) UIButton *startBtn;
@property (nonatomic, strong) NSArray *adjustedItems;
@property (nonatomic, strong) NSMutableArray *adjustedCells;
@property (nonatomic, strong) NSMutableArray *sepLines;
@property (nonatomic, strong) UILabel *adviceMessageLab;
@end
@implementation StartReadyView
- (instancetype)initWithDelegate:(id<StartReadyViewDelegate>)delegate {
if (self = [super initWithFrame:[UIScreen mainScreen].bounds]) {
_delegate = delegate;
self.adjustedItems = [NSArray array];
self.adjustedCells = [NSMutableArray array];
self.sepLines = [NSMutableArray array];
[self addSubview:self.headIV];
[self addSubview:self.startBtn];
[self addSubview:self.adviceMessageLab];
[self.headIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.equalTo(self);
}];
[self.startBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(155, 40));
make.centerX.equalTo(self);
make.bottom.equalTo(self).offset(-94-Bottom_SafeArea_Height);
}];
[self.adviceMessageLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
make.left.equalTo(self).offset(5);
make.right.equalTo(self).offset(-5);
make.top.equalTo(self.startBtn.mas_bottom).offset(10);
}];
}
return self;
}
- (void)updateAdjustView:(NSArray *)adjustedItems {
// 移除所有cell
for (ItemCell *cell in self.adjustedCells) {
[cell removeFromSuperview];
}
[self.adjustedCells removeAllObjects];
// 移除所有分割线
for (LineView *lineV in self.sepLines) {
[lineV removeFromSuperview];
}
[self.sepLines removeAllObjects];
// 新建所有cell和分割线
self.adjustedItems = [adjustedItems copy];
CGFloat itemH = 102;
CGFloat y = 310;
CGFloat left_right_margin = 30;
CGFloat itemW = (self.width - 2*left_right_margin)/adjustedItems.count;
for (int index = 0; index < adjustedItems.count; index++) {
ItemCell *cell = [[ItemCell alloc] initWithFrame:CGRectMake(left_right_margin + index*itemW, y, itemW, itemH)];
cell.item = adjustedItems[index];
[self addSubview:cell];
[self.adjustedCells addObject:cell];
}
if (adjustedItems.count > 1) { // 至少是2个cell
for (int index = 0; index < adjustedItems.count - 1; index++) {
ItemCell *leftCell = self.adjustedCells[index > 0 ? index : 0];
ItemCell *rightCell = self.adjustedCells[index + 1];
LineView *lineView = [LineView new];
[self addSubview:lineView];
[self.sepLines addObject:lineView];
[lineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(leftCell.icon.mas_right).offset(0);
make.right.equalTo(rightCell.icon.mas_left).offset(0);
make.height.equalTo(@6);
make.centerY.equalTo(leftCell.icon);
}];
}
}
}
- (void)updateAdviceMessage:(NSString *)adviceMessage {
self.adviceMessageLab.text = adviceMessage;
}
#pragma mark - lazy
- (UIImageView *)headIV {
if (!_headIV) {
_headIV = [UIImageView new];
_headIV.dk_imagePicker = DKImagePickerWithNames(@"bg_anshui_start", @"dk_bg_anshui_start", @"bg_anshui_start");
}
return _headIV;
}
- (UIButton *)startBtn {
if (!_startBtn) {
WS(weakSelf);
_startBtn = [UIButton btnWithTitle:@"开始仪式" font:BoldFont(16.0)];
[_startBtn cornerRadius:20.0];
[_startBtn dk_setBackgroundColorPicker:DKColorPickerWithColors(BrandColor, SubNaviDarkColor, DSWhite)];
[_startBtn dk_setTitleColorPicker:DKColorPickerWithColors(DSWhite, DkTitleColor, DSWhite) forState:UIControlStateNormal];
[_startBtn addTouchUpInsideHandler:^(NSInteger tag) {
if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(startTask)]) {
[weakSelf.delegate startTask];
}
}];
}
return _startBtn;
}
- (UILabel *)adviceMessageLab {
if (!_adviceMessageLab) {
_adviceMessageLab = [UILabel labWithFont:SysFont(12.0)];
_adviceMessageLab.textAlignment = NSTextAlignmentCenter;
_adviceMessageLab.dk_textColorPicker = DKColorPickerWithColors(SubTitleColor, ColorFromHexA(0xFFFFFF, .3), DSWhite);
}
return _adviceMessageLab;
}
@end