CNLiveAlertTipView.m
6.25 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
//
// CNLiveAlertTipView.m
// CNLiveCServiceModule
//
// Created by CNLive on 2021/12/3.
//
#import "CNLiveAlertTipView.h"
@interface CNLiveAlertTipView()
@property (nonatomic, strong)UILabel *titleLabel;
@property (nonatomic, strong)UILabel *messageLabel;
@property (nonatomic, strong)UIButton *cancelBtn;
@property (nonatomic, strong)UIButton *sureBtn;
@property (nonatomic, strong)UIButton *notShowBtn;
@end
@implementation CNLiveAlertTipView
+ (void)showTipsInViewSureBlock:(void (^)(BOOL))sureBlock
{
CNLiveAlertTipView *tipView = [[CNLiveAlertTipView alloc] initWithFrame:CGRectMake(0, 0, 285, 379.5)];
tipView.backgroundColor = kWhiteColor;
tipView.layer.cornerRadius = 10;
[tipView addSubview:tipView.titleLabel];
[tipView addSubview:tipView.messageLabel];
[tipView addSubview:tipView.cancelBtn];
[tipView addSubview:tipView.sureBtn];
[tipView addSubview:tipView.notShowBtn];
tipView.titleLabel.text = @"免责声明";
[tipView.titleLabel sizeToFit];
[tipView.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(tipView).offset(25);
make.centerX.mas_equalTo(tipView);
}];
tipView.messageLabel.text = @"1、每人每天有5次投票机会,在网家家APP内参与该活动最多可投5票。在微信、QQ等平台参与该活动最多可投3票;投票机会0点重置。\n\n2、本活动禁止刷票,凡是通过非正常手段刷票获取票数的行为,系统检测到并核实后将取消参赛资格。凡是通过非正常手段刷票获取票数的行为,系统检测到并核实后将取消参赛资。";
[tipView.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(tipView.titleLabel.mas_bottom);
make.width.offset(255);
make.height.offset(185);
make.centerX.mas_equalTo(tipView);
}];
[tipView.cancelBtn setTitle:@"拒绝" forState:UIControlStateNormal];
[tipView.sureBtn setTitle:@"接受" forState:UIControlStateNormal];
[tipView.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(tipView).offset(15);
make.bottom.equalTo(tipView).offset(-20);
make.width.offset(120);
make.height.offset(39);
}];
[tipView.sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(tipView).offset(-15);
make.bottom.equalTo(tipView.cancelBtn);
make.width.offset(120);
make.height.offset(39);
}];
[tipView.notShowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(tipView.cancelBtn.mas_top).offset(-10);
make.width.offset(105);
make.height.offset(20);
make.left.equalTo(tipView).offset(15);
}];
QMUIModalPresentationViewController *modalViewController = [[QMUIModalPresentationViewController alloc] init];
modalViewController.contentView = tipView;
modalViewController.modal = YES;
[modalViewController showWithAnimated:YES completion:nil];
__weak typeof(modalViewController) weakModalViewController = modalViewController;
__weak typeof(tipView) weakTipView = tipView;
[tipView.cancelBtn addBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) {
[weakModalViewController hideWithAnimated:YES completion:nil];
}];
[tipView.sureBtn addBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) {
[weakModalViewController hideWithAnimated:YES completion:^(BOOL finished) {
if (finished&&sureBlock) {
sureBlock(weakTipView.notShowBtn.isSelected);
}
}];
}];
}
#pragma mark - Action
-(void)notShowBtnClick:(UIButton *)sender{
sender.selected = !sender.isSelected;
}
#pragma mark - Getting&&Setting
- (UILabel *)titleLabel
{
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.textAlignment = NSTextAlignmentCenter;
_titleLabel.textColor = CNLiveColorWithHexString(@"#333333");
_titleLabel.font = UIFontMake(17);
}
return _titleLabel;
}
-(UILabel *)messageLabel
{
if (!_messageLabel) {
_messageLabel = [[UILabel alloc] init];
_messageLabel.textAlignment = NSTextAlignmentCenter;
_messageLabel.textColor = CNLiveColorWithHexString(@"#333333");
_messageLabel.font = UIFontMake(13);
_messageLabel.numberOfLines = 0;
}
return _messageLabel;
}
-(UIButton *)cancelBtn
{
if (!_cancelBtn) {
_cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_cancelBtn setTitleColor:CNLiveColorWithHexString(@"#999999") forState:UIControlStateNormal];
_cancelBtn.layer.cornerRadius = 21;
_cancelBtn.titleLabel.font = UIFontMake(16);
_cancelBtn.backgroundColor = CNLiveColorWithHexString(@"#EEEEEE");
}
return _cancelBtn;
}
-(UIButton *)sureBtn
{
if (!_sureBtn) {
_sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_sureBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
_sureBtn.layer.cornerRadius = 21;
_sureBtn.titleLabel.font = UIFontMake(16);
_sureBtn.backgroundColor = [UIColor colorWithPatternImage:[UIImage gradientVerticalImageWithColors:@[CNLiveColorWithHexString(@"#FFAA4A"),CNLiveColorWithHexString(@"#EC5645")] rect:CGRectMake(0, 0, 120, 39)]];
}
return _sureBtn;
}
- (UIButton *)notShowBtn
{
if (!_notShowBtn) {
_notShowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_notShowBtn setImage:[UIImage loadCServiceBundle:@"tips_no"] forState:UIControlStateNormal];
[_notShowBtn setImage:[UIImage loadCServiceBundle:@"tips_select"] forState:UIControlStateSelected];
_notShowBtn.backgroundColor = kClearColor;
[_notShowBtn setTitle:@"下次不再弹出" forState:UIControlStateNormal];
[_notShowBtn setTitleColor:CNLiveColorWithHexString(@"#F5A623") forState:UIControlStateNormal];
[_notShowBtn setTitle:@"下次不再弹出" forState:UIControlStateSelected];
[_notShowBtn setTitleColor:CNLiveColorWithHexString(@"#F5A623") forState:UIControlStateSelected];
_notShowBtn.titleLabel.font = UIFontMake(14);
[_notShowBtn addTarget:self action:@selector(notShowBtnClick:) forControlEvents:UIControlEventTouchUpInside];
}
return _notShowBtn;
}
@end