CNLiveUpdateTelController.m
9.47 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
//
// CNLiveUpdateTelController.m
// CNLiveSettingModule
//
// Created by 153993236@qq.com on 11/12/2019.
// Copyright (c) 2019 153993236@qq.com. All rights reserved.
//
#import "CNLiveUpdateTelController.h"
#import "CNLiveChooseCountryController.h"
#import "YYKit.h"
#import <Masonry/Masonry.h>
#import "QMUIKit.h"
#import <CNLiveUserSystemSDK/CNLiveUserSystemCenter.h>
#import "CNUserInfoManager.h"
#import "NSString+CNLiveExtension.h"
#import "CNLiveSettingNavigationBar.h"
#import "CNLiveUpdateTelView.h"
@interface CNLiveUpdateTelController()<UITextFieldDelegate, CNLiveSettingNavigationBarDelegate, CNLiveUpdateTelViewDelegate, ChooseCountriesDelegate>
@property (nonatomic, strong) CNLiveSettingNavigationBar *navigationBar;
@property (nonatomic, strong) CNLiveUpdateTelView *updateTel;//背景
@property (nonatomic, strong) YYLabel *connection;
@end
@implementation CNLiveUpdateTelController
static const NSInteger timeValue = 1.5;
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1.0];
[self createSubViews];
[self xw_layoutSubviews];
__weak typeof(self) weakSelf = self;
QMUIAlertAction *sure = [QMUIAlertAction actionWithTitle:@"确定" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
}];
QMUIAlertAction *cancel = [QMUIAlertAction actionWithTitle:@"取消" style:QMUIAlertActionStyleCancel handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
__strong typeof(weakSelf) strongSelf = weakSelf;
if(!strongSelf) return ;
[strongSelf.navigationController popViewControllerAnimated:YES];
}];
QMUIAlertController *alertController = [QMUIAlertController alertControllerWithTitle:@"更换手机号将只能使用新绑定的手机号登录app,是否继续修改?" message:@"" preferredStyle:QMUIAlertControllerStyleAlert];
[alertController addAction:sure];
[alertController addAction:cancel];
NSMutableDictionary *titleAttributs = [[NSMutableDictionary alloc] initWithDictionary:alertController.alertTitleAttributes];
titleAttributs[NSForegroundColorAttributeName] = [UIColor colorWithRed:35/255.0 green:212/255.0 blue:30/255.0 alpha:1.0];
NSMutableDictionary *cancelAttributs = [[NSMutableDictionary alloc] initWithDictionary:alertController.alertTitleAttributes];
cancelAttributs[NSForegroundColorAttributeName] = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
sure.buttonAttributes = titleAttributs;
cancel.buttonAttributes = cancelAttributs;
[alertController showWithAnimated:YES];
}
#pragma mark - UI
- (void)createSubViews{
[self.view addSubview:self.navigationBar];
[self.view addSubview:self.updateTel];
[self.view addSubview:self.connection];
}
- (void)xw_layoutSubviews{
[self.updateTel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view);
make.top.equalTo(self.view).offset(NavigationContentTop+1);
make.height.mas_equalTo(220);
}];
[self.connection mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view);
make.bottom.equalTo(self.view.mas_bottom).offset(-30);
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - ChooseCountriesDelegate
- (void)chooseViewController:(CNLiveChooseCountryController *)controller countryName:(NSString *)name countryCode:(NSString *)code{
_updateTel.countryName.text = name;
_updateTel.countryCode.text = [NSString stringWithFormat:@"+%@",code];
_updateTel.codeNum = code;
}
#pragma mark - CNLiveUpdateTelViewDelegate
- (void)selectCountry:(CNLiveUpdateTelView *)view{
CNLiveChooseCountryController *vc = [[CNLiveChooseCountryController alloc]init];
vc.delegate = self;
vc.hidesBottomBarWhenPushed = YES;
[self presentViewController:vc animated:YES completion:nil];
}
- (void)bindingSuccess:(CNLiveUpdateTelView *)view{
[self.navigationController popViewControllerAnimated:YES];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self.updateTel.telTF resignFirstResponder];
}
#pragma mark - Lazy Loading
- (CNLiveSettingNavigationBar *)navigationBar {
if (!_navigationBar) {
_navigationBar = [[CNLiveSettingNavigationBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationContentTop)];
_navigationBar.backgroundColor = [UIColor whiteColor];
_navigationBar.delegate = self;
_navigationBar.title.text = @"更换手机号";
_navigationBar.right = nil;
}
return _navigationBar;
}
- (CNLiveUpdateTelView *)updateTel{
if (!_updateTel) {
_updateTel = [[CNLiveUpdateTelView alloc] init];
_updateTel.delegate = self;
_updateTel.codeNum = @"86";
}
return _updateTel;
}
- (YYLabel *)connection {
if (!_connection) {
_connection = [[YYLabel alloc] init];
[_connection setFont:UIFontMake(12)];
_connection.numberOfLines = 0;
NSString *str = @"若当前号码已不用或丢失,请点击联系客服";
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:str];
text.color = [UIColor colorWithRed:34/255.0 green:34/255.0 blue:34/255.0 alpha:1.0];
[text setTextHighlightRange:NSMakeRange(text.length-4, 4) color:[UIColor colorWithRed:44/255.0 green:209/255.0 blue:201/255.0 alpha:1.0] backgroundColor:[UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1.0] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
NSString *phoneStr = @"010-65832485";
QMUIAlertAction *sure = [QMUIAlertAction actionWithTitle:@"好" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
if (@available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneStr]] options:@{} completionHandler:nil];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneStr]]];
}
}];
QMUIAlertAction *cancel = [QMUIAlertAction actionWithTitle:@"取消" style:QMUIAlertActionStyleCancel handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
}];
QMUIAlertController *alertController = [QMUIAlertController alertControllerWithTitle:@"联系客服" message:[NSString stringWithFormat:@"将给%@拨打电话",phoneStr] preferredStyle:QMUIAlertControllerStyleAlert];
[alertController addAction:sure];
[alertController addAction:cancel];
NSMutableDictionary *titleAttributs = [[NSMutableDictionary alloc] initWithDictionary:alertController.alertTitleAttributes];
titleAttributs[NSForegroundColorAttributeName] = [UIColor colorWithRed:35/255.0 green:212/255.0 blue:30/255.0 alpha:1.0];
NSMutableDictionary *cancelAttributs = [[NSMutableDictionary alloc] initWithDictionary:alertController.alertTitleAttributes];
cancelAttributs[NSForegroundColorAttributeName] = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
sure.buttonAttributes = titleAttributs;
cancel.buttonAttributes = cancelAttributs;
[alertController showWithAnimated:YES];
} ];
_connection.attributedText = text;
_connection.textAlignment = NSTextAlignmentCenter;
}
return _connection;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
/**
* 创建图片
*
* @param imageName 图片名字
* @param bundleName 图片所在的bundle名字
* @param targetClass 类和bundle的同级目录
* @return 返回UIImage
*/
- (UIImage *)xw_getImageName:(NSString *)imageName bundleName:(NSString *)bundleName targetClass:(Class)targetClass{
NSBundle *bundle = [NSBundle bundleForClass:targetClass];
NSURL *url = [bundle URLForResource:bundleName withExtension:@"bundle"];
NSBundle *targetBundle = [NSBundle bundleWithURL:url];
UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil];
return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil];
}
#pragma mark - CNLiveSettingNavigationBarDelegate
- (void)navigationBar:(CNLiveSettingNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{
if ([actionEvents isEqualToString:@"1"]) {
[self.navigationController popViewControllerAnimated:YES];
}else if ([actionEvents isEqualToString:@"2"]){
}
}
@end