SRTipsView.m
4.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
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
//
// SRTipsView.m
// DreamSleep
//
// Created by peter on 2022/7/11.
//
#import "SRTipsView.h"
@interface SRTipsView ()
@property (nonatomic, strong) UIView *alertView;
@property (nonatomic, strong) UIImageView *topIV;
@property (nonatomic, strong) UIImageView *midIV;
@property (nonatomic, strong) UILabel *tipsLab;
@property (nonatomic, strong) UIButton *gotBtn;
@property (nonatomic, strong) UIButton *closeBtn;
@end
@implementation SRTipsView
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:[UIScreen mainScreen].bounds]) {
self.dk_backgroundColorPicker = DKColorPickerWithColors(ColorFromHex(0x6F7587), DSClearColor, DSWhite);
self.backgroundColor = [self.backgroundColor colorWithAlphaComponent:0.6];
[self addSubview:self.alertView];
[self.alertView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self);
make.width.equalTo(@280);
make.height.mas_greaterThanOrEqualTo(100);
}];
}
return self;
}
- (void)showTipsAlertView {
[DSKeyWindow addSubview:self];
}
- (void)dismissTipsAlertView {
[self removeFromSuperview];
}
#pragma mark - lazy
- (UIView *)alertView {
if (!_alertView) {
_alertView = [UIView new];
_alertView.dk_backgroundColorPicker = DKColorPickerWithColors(DSWhite, AlertDarkColor, DSWhite);
[_alertView cornerRadius:23.0];
[_alertView addSubview:self.topIV];
[_alertView addSubview:self.midIV];
[_alertView addSubview:self.tipsLab];
[_alertView addSubview:self.gotBtn];
[_alertView addSubview:self.closeBtn];
[self.topIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.equalTo(_alertView);
}];
[self.midIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(_alertView);
make.top.equalTo(@75);
}];
[self.tipsLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_alertView).offset(15);
make.right.equalTo(_alertView).offset(-15);
make.top.equalTo(self.midIV.mas_bottom).offset(15);
}];
[self.gotBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(_alertView);
make.top.equalTo(self.tipsLab.mas_bottom).offset(30);
make.bottom.equalTo(_alertView).offset(-24);
make.size.mas_equalTo(CGSizeMake(155, 40));
}];
[self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_alertView).offset(15);
make.right.equalTo(_alertView).offset(-15);
}];
}
return _alertView;
}
- (UIImageView *)topIV {
if (!_topIV) {
_topIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg_pop"]];
}
return _topIV;
}
- (UIImageView *)midIV {
if (!_midIV) {
_midIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ic_pop_light"]];
}
return _midIV;
}
- (UILabel *)tipsLab {
if (!_tipsLab) {
NSString *tips = @"我们无法掌握入睡后的行动,却可以通过睡前30分钟的放松活动帮助放松大脑和身体,从而高效入眠。长期坚持,可有效改善睡眠质量。";
_tipsLab = [UILabel labWithText:tips font:SysFont(14.0) fit:YES];
_tipsLab.numberOfLines = 0;
_tipsLab.dk_textColorPicker = DKColorPickerWithColors(SubTitleColor, ColorFromHexA(0xFFFFFF, .5), DSWhite);
}
return _tipsLab;
}
- (UIButton *)gotBtn {
if (!_gotBtn) {
WS(weakSelf);
_gotBtn = [UIButton btnWithTitle:@"我知道了" font:BoldFont(16.0)];
[_gotBtn cornerRadius:20.0];
[_gotBtn dk_setBackgroundColorPicker:DKColorPickerWithColors(BrandColor, SubNaviDarkColor, DSWhite)];
[_gotBtn dk_setTitleColorPicker:DKColorPickerWithColors(DSWhite, DkTitleColor, DSWhite) forState:UIControlStateNormal];
[_gotBtn addTouchUpInsideHandler:^(NSInteger tag) {
[weakSelf dismissTipsAlertView];
}];
}
return _gotBtn;
}
- (UIButton *)closeBtn {
if (!_closeBtn) {
WS(weakSelf);
_closeBtn = [UIButton new];
[_closeBtn dk_setImage:DKImagePickerWithNames(@"dk_home_close", @"home_close", @"home_close") forState:UIControlStateNormal];
[_closeBtn addTouchUpInsideHandler:^(NSInteger tag) {
[weakSelf dismissTipsAlertView];
}];
}
return _closeBtn;
}
@end