美文网首页
备忘录-账号,密码和短信倒计时相关

备忘录-账号,密码和短信倒计时相关

作者: Mn_Su | 来源:发表于2016-09-23 13:03 被阅读0次

一.创建账号和密码控件

    -(void)createKit
    {
        self.view.backgroundColor = BGCOLOR;
        
        self.phoneTF = [[UITextField alloc]initWithFrame:CGRectMake(10, 100, WIDTH - 20, 40)];
        self.phoneTF.placeholder = @"    请输入手机号码";
        self.phoneTF.textColor = TEXTCOLOR;
        self.phoneTF.backgroundColor = [UIColor whiteColor];
        self.phoneTF.font = [UIFont systemFontOfSize:16];
        self.phoneTF.layer.cornerRadius = 3;
        self.phoneTF.clipsToBounds = YES;
        self.phoneTF.delegate = self;
        self.phoneTF.keyboardType = UIKeyboardTypeNumberPad;
        [self.view addSubview:self.phoneTF];
        self.identifyingTF = [[UITextField alloc]initWithFrame:CGRectMake(10, 150, WIDTH - 130, 40)];
        self.identifyingTF.placeholder = @"    请输入验证码";
        self.identifyingTF.textColor = TEXTCOLOR;
        self.identifyingTF.backgroundColor = [UIColor whiteColor];
        self.identifyingTF.font = [UIFont systemFontOfSize:16];
        self.identifyingTF.layer.cornerRadius = 3;
        self.identifyingTF.clipsToBounds = YES;
        self.identifyingTF.keyboardType = UIKeyboardTypeNumberPad;
        [self.view addSubview:self.identifyingTF];
        
        UIButton *identifyingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        identifyingBtn.frame = CGRectMake(WIDTH - 120, 150, 110, 40);
        identifyingBtn.layer.cornerRadius = 3;
        identifyingBtn.clipsToBounds = YES;
        [identifyingBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
        identifyingBtn.titleLabel.font = [UIFont systemFontOfSize:16];
        [identifyingBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [identifyingBtn addTarget:self action:@selector(identifyingBtnClick) forControlEvents:UIControlEventTouchUpInside];
        identifyingBtn.backgroundColor = GREENCOLOR;
        [self.view addSubview:identifyingBtn];
        
        UIButton *nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        nextBtn.frame = CGRectMake(10, 240, WIDTH - 20, 40);
        [nextBtn setTitle:@"下一步" forState:UIControlStateNormal];
        [nextBtn addTarget:self action:@selector(nextBtnClick) forControlEvents:UIControlEventTouchUpInside];
        nextBtn.layer.cornerRadius = 3;
        nextBtn.clipsToBounds = YES;
        nextBtn.backgroundColor = GREENCOLOR;
        [self.view addSubview:nextBtn];
    }

二.点击验证按钮方法

    -(void)identifyingBtnClick
    {
        NSLog(@"获取验证码");
        self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(changeTime) userInfo:nil repeats:YES];
        self.identifingBg = [[UIView alloc]initWithFrame:CGRectMake(WIDTH - 120, 150, 110, 40)];
        self.identifingBg.layer.cornerRadius = 3;
        self.identifingBg.clipsToBounds = YES;
        self.identifingBg.backgroundColor = RGBCOLOR(95, 165, 50);
        [self.view addSubview:self.identifingBg];
        
        self.timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 110, 40)];
        self.timeLabel.text = @"倒计时(60s)";
        self.timeLabel.textColor = [UIColor whiteColor];
        self.timeLabel.font = [UIFont systemFontOfSize:16];
        self.timeLabel.textAlignment = NSTextAlignmentCenter;
        [self.identifingBg addSubview:self.timeLabel];
        
        time = 0;
    }

三.NSTimer相关方法

    -(void)changeTime
    {
        time ++;
        int value = 60 - time;
        if (value >= 0) {
            self.timeLabel.text = [NSString stringWithFormat:@"倒计时(%ds)",value];
        }else
        {
            [self.timer invalidate];
            [self.identifingBg removeFromSuperview];
        }
    }

四.回收键盘方法

    -(void)textFieldDidEndEditing:(UITextField *)textField
    {
            [self checkTel:self.phoneTF.text];
    }
    
    -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    {
        [self.view endEditing:YES];
    }

五.检验号码方法

    - (BOOL)checkTel:(NSString *)str
    
    {
        
        if ([str length] == 0) {
            
            ALERTVIEW(@"手机号码不能为空");
            
            
            return NO;
            
        }
        
        //1[0-9]{10}
        
        //^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$
        
        //    NSString *regex = @"[0-9]{11}";
        
        NSString *regex = @"^((13[0-9])|(17[0-9])|(147)|(15[^4,\\D])|(18[0,1,5-9]))\\d{8}$";
        
        NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
        
        BOOL isMatch = [pred evaluateWithObject:str];
        
        if (!isMatch) {
            
            UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请输入正确的手机号码" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            
            [alert show];
            
            return NO;
            
        }
        
        
        
        return YES;
        
    }

相关文章

  • 备忘录-账号,密码和短信倒计时相关

    一.创建账号和密码控件 二.点击验证按钮方法 三.NSTimer相关方法 四.回收键盘方法 五.检验号码方法

  • 忘记密码

    现在各种账号,密码随着账号走,除手机支付宝密码经常用记得以外,其它密码找回主要靠手机短信了。 这张银行卡的秘码前一...

  • 短信验证码的实现

    首先在阿里云上注册自己的账号和密码,然后短信模板和短信签名是比较重要的,需要申请成功之后才可以使用阿里云上给你提供...

  • ios 开发之UIWebView 通过 cookie 完成自动登

    相信使用过UIWebView的小伙伴都遇见过在webView中输入相关账号和密码这样类似的情况,但在我们输入账号和...

  • 苏大移动宽带网络连接指导手册

    一.在连接移动网络之前,请确认是否收到移动开通宽带的相关短信和开通宽带的宽带密码(默认宽带密码:123321) 二...

  • 在线随机密码生成器

    由于平常工作原因,需要管理很多数据库,服务器,及相关账号,这就需要经常生成和更换密码。为了保证密码的安全性,密码需...

  • iOS 短信验证码倒计时

    本文完整Demo 项目中很常用的发送短信验证码倒计时功能(登录、注册、忘记密码、修改支付密码等) 对于这种功能大家...

  • 2014.05.13再发迅雷vip帐号

    账号145582402:2密码0848301 账号sk908812密码35330927 账号ymooiaaib密码...

  • 2014.5.24vip迅雷e

    账号176647045密码79005533 账号796365623密码fenxs.com 账号cs666154密码...

  • sqlite 的分布式实现方案:rqlite

    rqlite 相关操作说明 项目总为实现 sqlite 添加账号和密码,以满足信息安全的需求。鉴于对 sqlite...

网友评论

      本文标题:备忘录-账号,密码和短信倒计时相关

      本文链接:https://www.haomeiwen.com/subject/eketyttx.html