| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- //
- // UserRegister_VC.m
- // Haishenghai-master
- //
- // Created by GG on 2018/12/29.
- // Copyright © 2018年 Haishenghai intelligence network technology. All rights reserved.
- //
- #import "UserRegister_VC.h"
- #import "Header.h"
- #import "privacy_VC.h"
- #import "Protcol_VC.h"
- @interface UserRegister_VC ()<UITextFieldDelegate>
- @end
- @implementation UserRegister_VC
- - (void)viewDidLoad {
- [super viewDidLoad];
- //导航栏添加返回按钮
- self.navigationItem.title = @"注册";
- //改变返回按钮的箭头和颜色
- [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor colorWithRed:66/255.0 green:66/255.0 blue:66/255.0 alpha:1]}];
- //设置导航栏左侧按钮
- UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [backBtn setImage:[UIImage imageNamed:@"hsh_register_return"] forState:UIControlStateNormal];
- backBtn.frame = CGRectMake(0, 0, 44, 44);
- [backBtn addTarget:self action:@selector(backBtnClick) forControlEvents:UIControlEventTouchUpInside];
- backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
-
- //
- [self setupUI];
- }
- #pragma mark -Set UI
- -(void)setupUI{
- /** 设置背景 */
- self.view.backgroundColor = [UIColor whiteColor];
- /** 设置返回 */
- // self.backBtn.frame = CGRectMake(10, 20, 30, 30);
- // [self.backBtn setBackgroundImage:[UIImage imageNamed:@"hsh_register_return"] forState:UIControlStateNormal];
- // [self.backBtn setTitle:@"返回" forState:UIControlStateNormal];
- // [self.backBtn addTarget:self action:@selector(backBtnClick) forControlEvents:UIControlEventTouchUpInside];
- // [self.view addSubview:self.backBtn];
-
-
- /** 设置logo */
- [self.logoImageView setImage:[UIImage imageNamed:@"logo"]];
- self.logoImageView.frame = CGRectMake(WIDTH/2-55, HEIGHT/4-75, 110, 110);
- [self.view addSubview:self.logoImageView];
-
- /** 设置内容视图 */
-
- /**设置姓名输入框 */
- self.accountTF.frame = CGRectMake(20, HEIGHT/2-88, WIDTH-40, 44);
- self.accountTF.placeholder = @"请输入昵称";
- self.accountTF.tintColor = [UIColor blueColor];
- self.accountTF.textColor = [UIColor blackColor];
- self.accountTF.font = [UIFont systemFontOfSize:18];
- self.accountTF.leftViewMode = UITextFieldViewModeAlways;
- self.accountTF.clearsOnBeginEditing = YES;
- self.accountTF.clearButtonMode = UITextFieldViewModeWhileEditing;
- //自动修正
- self.accountTF.autocorrectionType = UITextAutocorrectionTypeDefault;
- self.accountTF.delegate = self;
- //设置左边视图
- UIImageView *userImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
- userImage.contentMode = UIViewContentModeLeft;
- //??
- userImage.image = [UIImage imageNamed:@"hsh_login_user"];
- self.accountTF.leftView = userImage;
- [self.view addSubview:self.accountTF];
- UIView *accountLine = [[UIView alloc]init];
- //??
- accountLine.frame = CGRectMake(0, 43.5, WIDTH-40, 0.5);
- accountLine.backgroundColor = [UIColor grayColor];
- self.accountLine = accountLine;
- [self.accountTF addSubview:accountLine];
-
- /**设置手机号输入框 */
- self.phoneTf.frame = CGRectMake(20, HEIGHT/2-44, WIDTH-40, 44);
- self.phoneTf.placeholder = @"请输入手机号";
- self.phoneTf.tintColor = [UIColor blueColor];
- self.phoneTf.textColor = [UIColor blackColor];
- self.phoneTf.font = [UIFont systemFontOfSize:18];
- self.phoneTf.leftViewMode = UITextFieldViewModeAlways;
- self.phoneTf.clearsOnBeginEditing = YES;
- self.phoneTf.clearButtonMode =UITextFieldViewModeWhileEditing;
- self.phoneTf.autocorrectionType = UITextAutocorrectionTypeDefault;
- self.phoneTf.delegate = self;
- //设置左边视图
- UIImageView *phoneImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
- phoneImage.contentMode = UIViewContentModeLeft;
- phoneImage.image = [UIImage imageNamed:@"hsh_register_tel"];
- self.phoneTf.leftView = phoneImage;
- [self.view addSubview:self.phoneTf];
- UIView *phoneLine = [[UIView alloc]init];
- //??
- phoneLine.frame = CGRectMake(0, 43.5, WIDTH-40, 0.5);
- phoneLine.backgroundColor = [UIColor grayColor];
- _phoneLine = phoneLine;
- [self.phoneTf addSubview:self.phoneLine];
-
-
- /** 设置手机验证码输入框 */
- self.smsCodeTF.frame = CGRectMake(20, HEIGHT/2, WIDTH-40, 44);
- self.smsCodeTF.placeholder = @"请输入手机验证码";
- self.smsCodeTF.tintColor = [UIColor blueColor];
- self.smsCodeTF.textColor = [UIColor blackColor];
- self.smsCodeTF.font = [UIFont systemFontOfSize:18];
- self.smsCodeTF.leftViewMode = UITextFieldViewModeAlways;
- // self.smsCodeTF.clearsOnBeginEditing =YES;
- // self.smsCodeTF.clearButtonMode = UITextFieldViewModeWhileEditing;
- self.smsCodeTF.autocorrectionType = UITextAutocorrectionTypeDefault;
- self.smsCodeTF.delegate = self;
- //设置左边视图
- UIImageView *smsImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
- smsImage.contentMode = UIViewContentModeLeft;
- smsImage.image = [UIImage imageNamed:@"hsh_register_verification"];
- self.smsCodeTF.leftView = smsImage;
- [self.view addSubview:self.smsCodeTF];
- UIView *smsLine = [[UIView alloc]init];
- //??
- smsLine.frame = CGRectMake(0, 43.5, WIDTH-40, 0.5);
- smsLine.backgroundColor = [UIColor grayColor];
- self.smsLine = smsLine;
- [self.smsCodeTF addSubview:self.smsLine];
- /**设置获取验证码button */
- self.resetPasswordBtn.frame = CGRectMake(self.smsCodeTF.frame.size.width-100, 5, 100, 34);
- self.resetPasswordBtn.layer.cornerRadius = 12;
- self.resetPasswordBtn.backgroundColor = [UIColor colorWithRed:113/255.0 green:154/255.90 blue:254/255.0 alpha:1];
- [self.resetPasswordBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
- [self.resetPasswordBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- self.resetPasswordBtn.titleLabel.textColor = [UIColor whiteColor];
- self.resetPasswordBtn.titleLabel.font = [UIFont systemFontOfSize:16];
- self.resetPasswordBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
- [self.resetPasswordBtn addTarget:self action:@selector(getSMSCodeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
- [self.smsCodeTF addSubview:self.resetPasswordBtn];
-
- /**设置密码输入框 */
- self.passwordTF.frame = CGRectMake(20, HEIGHT/2+44, WIDTH-40, 44);
- self.passwordTF.placeholder = @"请输入密码";
- self.passwordTF.tintColor = [UIColor blueColor];
- self.passwordTF.textColor = [UIColor blackColor];
- self.passwordTF.font = [UIFont systemFontOfSize:18];
- self.passwordTF.leftViewMode = UITextFieldViewModeAlways;
- self.passwordTF.delegate = self;
- self.passwordTF.secureTextEntry =YES;//密文输入
- self.passwordTF.clearButtonMode = UITextFieldViewModeWhileEditing;
- self.passwordTF.autocorrectionType = UITextAutocorrectionTypeDefault;
- //设置左边视图
- UIImageView *passwordImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
- passwordImage.contentMode = UIViewContentModeLeft;
- //??
- passwordImage.image = [UIImage imageNamed:@"hsh_login_password"];
- self.passwordTF.leftView = passwordImage;
- [self.view addSubview:self.passwordTF];
- UIView *passwordLine = [[UIView alloc]init];
- //??
- passwordLine.frame = CGRectMake(0, 43.5, WIDTH-40, 0.5);
- passwordLine.backgroundColor = [UIColor grayColor];
- self.passwordLine = passwordLine;
- [self.passwordTF addSubview:passwordLine];
-
- /** 设置确认密码 */
- self.confirmPasswordTf.frame = CGRectMake(20, HEIGHT/2+88, WIDTH-40, 44);
- self.confirmPasswordTf.placeholder = @"请再次确认密码";
- self.confirmPasswordTf.tintColor = [UIColor blueColor];
- self.confirmPasswordTf.textColor = [UIColor blackColor];
- self.confirmPasswordTf.font = [UIFont systemFontOfSize:18];
- self.confirmPasswordTf.leftViewMode = UITextFieldViewModeAlways;
- self.confirmPasswordTf.secureTextEntry =YES;
- self.confirmPasswordTf.clearButtonMode = UITextFieldViewModeWhileEditing;
- self.confirmPasswordTf.autocorrectionType = UITextAutocorrectionTypeDefault;
- self.confirmPasswordTf.delegate = self;
- //设置左边视图
- UIImageView *confirmImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
- confirmImage.contentMode = UIViewContentModeLeft;
- confirmImage.image = [UIImage imageNamed:@"hsh_login_password"];
- self.confirmPasswordTf.leftView = confirmImage;
- [self.view addSubview:self.confirmPasswordTf];
- UIView *confirmLine = [[UIView alloc]init];
- //??
- confirmLine.frame = CGRectMake(0, 43.5, WIDTH-40, 0.5);
- confirmLine.backgroundColor = [UIColor grayColor];
- self.confirmLine = confirmLine;
- [self.confirmPasswordTf addSubview:self.confirmLine];
-
- /**设置注册Button */
- self.registButton.frame = CGRectMake(20, HEIGHT*0.75, self.view.frame.size.width-40, 44);
- self.registButton.layer.cornerRadius = 18;
- [self.registButton setBackgroundImage:[UIImage imageNamed:@"blue"] forState:UIControlStateNormal];
- [self.registButton setTitle:@"注册" forState:UIControlStateNormal];
- [self.registButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- self.registButton.titleLabel.font = [UIFont systemFontOfSize:18];
- self.registButton.titleLabel.textAlignment = NSTextAlignmentCenter;
- // self.loginButton.clipsToBounds = YES;
- [self.registButton addTarget:self action:@selector(registeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:self.registButton];
-
- //用户协议
- UILabel *protcolLabel = [[UILabel alloc]init];
- protcolLabel.frame = CGRectMake(WIDTH/2-110, HEIGHT*0.75+44, 110, 30);
- // protcolBtn.backgroundColor = [UIColor grayColor];
- [self.view addSubview:protcolLabel];
- protcolLabel.font = [UIFont systemFontOfSize:12];
- protcolLabel.text = @"注册即代表您同意";
- protcolLabel.textColor = [UIColor colorWithRed:66/255.0 green:66/255.0 blue:66/255.0 alpha:1];
- protcolLabel.textAlignment = NSTextAlignmentRight;
-
- //用户协议Button
- UIButton *protcolBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- protcolBtn.frame =CGRectMake(WIDTH/2, HEIGHT*0.75+44, 60, 30);
- [protcolBtn setTitle:@"用户协议" forState:UIControlStateNormal];
-
- [protcolBtn setTitleColor:[UIColor colorWithRed:78/255.0 green:105/255.0 blue:255/255.0 alpha:1] forState:UIControlStateNormal];
- protcolBtn.titleLabel.font = [UIFont systemFontOfSize:12];
- [protcolBtn addTarget:self action:@selector(onBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:protcolBtn];
-
- //隐私条款Button
- UIButton *privateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- privateBtn.frame =CGRectMake(WIDTH/2+60, HEIGHT*0.75+44, 60, 30);
- [privateBtn setTitle:@"隐私条款" forState:UIControlStateNormal];
- [privateBtn setTitleColor:[UIColor colorWithRed:78/255.0 green:105/255.0 blue:255/255.0 alpha:1] forState:UIControlStateNormal];
-
- privateBtn.titleLabel.font = [UIFont systemFontOfSize:12];
- [privateBtn addTarget:self action:@selector(onBtnClick2) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:privateBtn];
-
- /** 布局 */
- [self make_layout];
- }
- -(void)make_layout{
-
- }
- #pragma mark - Event response
- -(void)onBtnClick{
- //用户协议
- Protcol_VC *proVC = [[Protcol_VC alloc]init];
- [self.navigationController pushViewController:proVC animated:YES];
-
- }
- -(void)onBtnClick2{
- //隐私条款
- privacy_VC *pri = [[privacy_VC alloc]init];
- [self.navigationController pushViewController:pri animated:YES];
- }
- -(void)backBtnClick{
- [self.navigationController popViewControllerAnimated:YES];
- }
- -(void)getSMSCodeBtnClick:(UIButton *)codeBtn{
- if (self.phoneTf.text ==nil||self.phoneTf.text.length<11) {
- ALERTSHOW(@"手机号输入错误");
- return;
- }
-
- [self startTime];
- }
- -(void)startTime{
- // GCD类型
- __block int timeout=59; //倒计时时间
- dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
- dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
- dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
-
- dispatch_source_set_event_handler(_timer, ^{
- if(timeout<=0){ //倒计时结束,关闭
- dispatch_source_cancel(_timer);
- dispatch_async(dispatch_get_main_queue(), ^{
- //设置界面的按钮显示 根据自己需求设置(倒计时结束后调用)
- //设置按钮的样式
- [self.resetPasswordBtn setTitle:@"重新发送" forState:UIControlStateNormal];
- //设置不可点击
- self.resetPasswordBtn.userInteractionEnabled = YES;
-
- });
- }else{
- // int minutes = timeout / 60; //这里注释掉了,这个是用来测试多于60秒时计算分钟的。
- int seconds = timeout % 60;
- NSString *strTime = [NSString stringWithFormat:@"%ds", seconds];
- dispatch_async(dispatch_get_main_queue(), ^{
- //设置界面的按钮显示 根据自己需求设置
- NSLog(@"____%@",strTime);
- [self.resetPasswordBtn setTitle:[NSString stringWithFormat:@"%@秒重发",strTime] forState:UIControlStateNormal];
- //设置可点击
- self.resetPasswordBtn.userInteractionEnabled = NO;
- });
- timeout--;
- }
- });
-
- dispatch_resume(_timer);
- //请求验证码
- [DataSourceManager getPhoneCodeWithPhone:self.phoneTf.text completionBlock:^(NSDictionary *dic) {
- ALERTSHOW(@"验证码发送成功");
- }];
- }
- -(void)registeBtnClick:(UIButton *)registBtn{
- [self show];
- [DataSourceManager setRegisterWithUrlPhoneNumber:self.phoneTf.text code:self.smsCodeTF.text UserName:self.accountTF.text PassWord1:self.passwordTF.text PassWord2:self.confirmPasswordTf.text completionBlock:^(NSDictionary *dic) {
- ALERTSHOW(@"注册成功");
- }];
- }
- #pragma mark------用户名密码校验
- -(void)show{
- //这里校验有问题
- if (self.accountTF.text ==nil/*||self.accountTF.text.length<11||self.accountTF.text.length >11*/) {
- [self.loginButton setEnabled:NO];
- [self.registButton setEnabled:NO];
- ALERTSHOW(@"手机号不能为空");
- return;
- }
-
- if (self.passwordTF.text ==nil||self.passwordTF.text.length>8){
- [self.loginButton setEnabled:NO];
- [self.registButton setEnabled:NO];
- ALERTSHOW(@"密码输入有误");
- return;
- }
- if (![self.passwordTF.text isEqualToString:self.confirmPasswordTf.text]) {
- ALERTSHOW(@"两次输入密码不相同");
- return;
- }
- }
- #pragma mark - Delegate methods
- - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
-
- return YES;
- }
- //避免键盘遮挡,登录表单或按钮上移代码
- - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
- NSTimeInterval animationDuration = 0.30f;
- [UIView beginAnimations:@ "ResizeForKeyboard" context:nil];
- [UIView setAnimationDuration:animationDuration];
-
- //将视图的Y坐标向上移动,以使下面腾出地方用于软键盘的显示
- self.view.frame = CGRectMake(0.0f, -50.0f, self.view.frame.size.width, self.view.frame.size.height); //64-216
-
- [UIView commitAnimations];
-
- return YES;
-
- }
- -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
-
- NSTimeInterval animationDuration = 0.30f;
- [UIView beginAnimations:@ "ResizeForKeyboard" context:nil];
- [UIView setAnimationDuration:animationDuration];
- //恢复屏幕
- self.view.frame = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, self.view.frame.size.height); //64-216
-
- [UIView commitAnimations];
- [[UIApplication sharedApplication].keyWindow endEditing:YES];
- }
- - (BOOL)textFieldShouldReturn:(UITextField *)textField {
- [textField resignFirstResponder];
- return YES;
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #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.
- }
- */
- @end
|