PrivacyView.m
5.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
//
// PrivacyView.m
// DreamSleep
//
// Created by peter on 2022/4/6.
//
#import "PrivacyView.h"
#import "PrivacyViewController.h"
#import "LeadingController.h"
@interface PrivacyView () <UITextViewDelegate>
@property (nonatomic, strong) UIView *bigView;
@property (nonatomic, strong) UILabel *setLb;
@property (nonatomic, strong) UIButton *cancelBtn;
@property (nonatomic, strong) UIButton *confirmBtn;
@property (nonatomic, strong) UITextView *textView;
@end
@implementation PrivacyView
-(void)layoutSubviews {
[super layoutSubviews];
[self initView];
}
- (void)initView {
self.bigView = [UIView new];
[self addSubview:self.bigView];
self.bigView.dk_backgroundColorPicker = DKColorPickerWithKey(TabBarBG);
self.bigView.layer.cornerRadius = 24;
self.bigView.layer.masksToBounds = YES;
[self.bigView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.mas_centerX);
make.centerY.equalTo(self.mas_centerY);
make.width.equalTo(@280);
make.height.equalTo(@236);
}];
self.setLb = [UILabel new];
[self.bigView addSubview:self.setLb];
self.setLb.text = @"隐私政策";
self.setLb.textAlignment = NSTextAlignmentCenter;
self.setLb.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
self.setLb.dk_textColorPicker = DKColorPickerWithKey(TEXT);
[self.setLb mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.bigView.mas_top);
make.left.equalTo(self.bigView.mas_left);
make.right.equalTo(self.bigView.mas_right);
make.height.equalTo(@40);
}];
self.cancelBtn = [UIButton new];
[self.bigView addSubview:self.cancelBtn];
[self.cancelBtn addTarget:self action:@selector(cancelBtnClick:) forControlEvents:UIControlEventTouchUpInside];
[self.cancelBtn setTitle:@"不同意" forState:UIControlStateNormal];
[self.cancelBtn dk_setTitleColorPicker:DKColorPickerWithKey(TEXT) forState:UIControlStateNormal];
self.cancelBtn.titleLabel.font = SysFont(16.0);
[self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.bigView.mas_left).offset(40);
make.bottom.equalTo(self.bigView.mas_bottom).offset(-12);
make.height.equalTo(@21);
make.width.equalTo(@60);
}];
self.confirmBtn = [UIButton new];
[self.bigView addSubview:self.confirmBtn];
[self.confirmBtn addTarget:self action:@selector(confirmBtnClick:) forControlEvents:UIControlEventTouchUpInside];
[self.confirmBtn setTitle:@"同意" forState:UIControlStateNormal];
[self.confirmBtn setTitleColor:BrandColor forState:UIControlStateNormal];
self.confirmBtn.titleLabel.font = SysFont(16.0);
[self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.bigView.mas_right).offset(-56);
make.bottom.equalTo(self.bigView.mas_bottom).offset(-12);
make.height.equalTo(@21);
make.width.equalTo(@60);
}];
self.textView = [UITextView new];
self.textView.delegate = self;
self.textView.editable = NO;
self.textView.backgroundColor = DSClearColor;
[self.bigView addSubview:self.textView];
// UITextView换行
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:PrivacyStatement attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]}];
// 设置行间距和段落间距
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:5];
[paragraphStyle setParagraphSpacing:5];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, PrivacyStatement.length)];
// 设置超链接文本样式
// MARK: 若NSLinkAttributeName字段包含中文时,需要对其进行特殊处理,否则无法触发UITextViewDelegate
[attributedString addAttributes:@{NSForegroundColorAttributeName:BrandColor, NSLinkAttributeName:UserServiceAgreement} range:[PrivacyStatement rangeOfString:@"用户服务协议"]];
[attributedString addAttributes:@{NSForegroundColorAttributeName:BrandColor, NSLinkAttributeName:PrivacyPolicy} range:[PrivacyStatement rangeOfString:@"隐私政策"]];
self.textView.linkTextAttributes = @{NSForegroundColorAttributeName:BrandColor};
self.textView.attributedText = attributedString;
self.textView.font = [UIFont systemFontOfSize:15];
self.textView.textColor = ColorFromRGB(145, 145, 145);
[self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.setLb.mas_bottom);
make.left.equalTo(self.bigView.mas_left).offset(5);
make.right.equalTo(self.bigView.mas_right).offset(-5);
make.bottom.equalTo(self.confirmBtn.mas_top).offset(-10);
}];
}
- (void)cancelBtnClick:(UIButton *)sender {
DSLog(@"%s", __func__);
}
- (void)confirmBtnClick:(UIButton *)sender {
// 本地存储隐私政策标识
kSetUserDefaultsBOOL(YES, FirstShowPrivacy);
kUserDefaultsSynchronize;
// 切换到引导页
DSKeyWindow.rootViewController = [[LeadingController alloc] init];
}
#pragma mark - UITextViewDelegate
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange interaction:(UITextItemInteraction)interaction {
NSString *title = [URL.absoluteString isEqualToString:UserServiceAgreement] ? @"用户服务协议" : @"隐私政策";
[self.ds_viewController.navigationController pushViewController:[[DsWebController alloc] initWithTitle:title link:URL.absoluteString] animated:YES];
return NO;
}
@end