iOS开发--验证码

第一步,拖两个空间textfiled和button到storyboard上的viewcontroller上。

屏幕快照 2015-08-05 下午11.53.36

第二步,拖线,链接到.h文件中代码如下:

1
@property (weak, nonatomic) IBOutlet UIButton *l_timeButton;

第三步,在,m文件中为l_timeButton设置监听器,监听点击事件。

1
2
3
4
- (void)viewDidLoad {
    [super viewDidLoad];
    [_l_timeButton addTarget:self action:@selector(startTime) forControlEvents:UIControlEventTouchUpInside];
}

第四步,在方法“startTime”中实现倒计时功能

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
-(void)startTime{
    __block int timeout=30; //倒计时时间
    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(), ^{
                //设置界面的按钮显示 根据自己需求设置
                [_l_timeButton setTitle:@"发送验证码" forState:UIControlStateNormal];
                _l_timeButton.userInteractionEnabled = YES;
            });
        }else{
            int seconds = timeout % 60;
            NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
            dispatch_async(dispatch_get_main_queue(), ^{
                //设置界面的按钮显示 根据自己需求设置
                //NSLog(@"____%@",strTime);
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:1];
                [_l_timeButton setTitle:[NSString stringWithFormat:@"%@秒后重新发送",strTime] forState:UIControlStateNormal];
                [UIView commitAnimations];
                _l_timeButton.userInteractionEnabled = NO;
            });
            timeout--;
        }
    });
    dispatch_resume(_timer);
}

一个验证码倒计时的功能就写好了

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/459025.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Standard C Episode 8

C语言函数和程序结构 通过函数可以把大的计算任务分解成若干个较小任务&#xff0c;从而使得思路更加清晰&#xff0c;同时函数也大大提高了代码的复用率&#xff0c;提高了工作效率。要注意的是多函数之间应该尽可能地高聚合低耦合。另一方面&#xff0c;一个程序可以保存在一…

C# Socket 编程详解

Microsoft.Net Framework为应用程序访问Internet提供了分层的、可扩展的以及受管辖的网络服务&#xff0c;其名字空间System.Net和 System.Net.Sockets包含丰富的类可以开发多种网络应用程序。.Net类采用的分层结构允许应用程序在不同的控制级别上访问网络&#xff0c;开发人员…

java 线程池 wait,Java 多线程 之 wait等待 线程实例

package com.wait.notify;/**题目: 人们在火车站的售票窗口排队买火车票1. 北京西站开门2. 打开售票窗口3. 北京西站有10张去长沙的票4. 打开2个售票窗口,5 假设每个售票窗口每隔1秒钟买完一张票1. 根据 名词 找类人们(Person), 火车站(Station),火车票(Ticket) , 售票窗口e 是…

002 exercises

求列表全排列lst [1,2,3] l1 [(x,y,z) for x in lst for y in lst for z in lst if x ! y if y ! z if x ! z] print(l1)给定一个非负整数num,重复的加每一位,直到最后只剩下一位例如: num 38,计算过程如下:3 8 111 1 2最后输出结果为2#递归 def add(num):if len(str(num…

(线段树 点更新 区间求和)lightoj1112

链接&#xff1a; http://acm.hust.edu.cn/vjudge/contest/view.action?cid88230#problem/D &#xff08;密码0817&#xff09; Description Robin Hood likes to loot rich people since he helps the poor people with this money. Instead of keeping all the money togeth…

TCP/ip通信模式

TCP/IP 应用层与应用程序*************************************************** 更多精彩&#xff0c;欢迎进入&#xff1a;http://shop115376623.taobao.com *************************************************** 文档出处&#xff1a;http://blog.csdn.net/bingxx11/article…

PHP中判断空的方法,php中类型判断和NULL,空值检查的方法

在一些接口和数据库的设计中。数据库的非必填字段可能为null或者为空。这个时候接口前端javascript去判断的时候就会比较麻烦。为了便于统一的判断。一律把null和 空装换成 空.这样前端的判断就变得简洁 if(aa ){........}建议使用 或者 来判断。。以下是我简短的一个把数据…

8 Regular Expressions You Should Know

2019独角兽企业重金招聘Python工程师标准>>> Regular expressions are a language of their own. When you learn a new programming language, theyre this little sub-language that makes no sense at first glance. Many times you have to read another tutori…

poj 3278 catch that cow BFS(基础水)

Catch That CowTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 61826 Accepted: 19329Description Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ 100,000) on a num…

制作已编译的html帮助文件

http://www.cnblogs.com/cm186man/archive/2008/03/10/1098896.html引用 HTML帮助文档从结构上来看可分为两个部分&#xff0c;运行器和文档内容。它的一个好处是能使帮助文档跨平台运行&#xff0c;只要有不同平台上的运行器和浏览器&#xff0c;帮助文档不再需要重新编制&…

matlab %3c handle,volume browser (updated).htm 源代码在线查看 - Matlab显式三维地震数据的源代码 资源下载 虫虫电子下载站...

Comments: any comments on this error:??? Error using > timesIntegers can only be combined with integers of the same class, or scalar doubles.Error in > interp3>linear at 368 F (( arg4(ndx).*(1-t) arg4(ndx1).*t ).*(1-s) ...Error in > inter…

PHPer转战Android的学习过程以及Android学习

原文作者&#xff1a; eoeadmin原文地址&#xff1a; http://my.eoe.cn/shuhai/archive/19684.html--------------------------------------------这篇文章主要写了一个PHP程序猿是如何转战学习Android的。 第一步&#xff1a;直接跨过java的学习&#xff0c;原因有我之前看过毕…

SQL中实现截取字符串的函数

SQL中实现截取字符串的函数 如果想实现从数据库中取数据时截取一个字段下的内容或者截取一串字符串&#xff0c;则能够实现这种效果的函数有Left&#xff0c;Right&#xff0c;SubString三个函数。1.Left函数&#xff1a;Left&#xff08;character_expression , integer_expre…

php时区设置问题,PHP 的时区设置问题_PHP教程

装上PHP5后你会发现这样的问题&#xff1a;你也许会发现&#xff0c;输出的时间和你现在的时间是不相同的。原因是假如你不在程序或配置文件中设置你的服务器当地时区的话&#xff0c;PHP所取的时间是格林威治标准时间&#xff0c;所以和你当地的时间会有出入。格林威治标准时间…

HDU 5392 BC #51

就是求最大公倍数&#xff0c;但要用分解质因子求。 自己写的WA到爆。。。。 #include<iostream> #include<stdio.h> #include<math.h>#include<algorithm>using namespace std;#define rd(x) scanf("%d",&x) #define rd2(x,y) scanf(&q…

下拉框——把一个select框中选中内容移到另一个select框中遇到的问题

在使用jQuery实现把一个select框中选中内容移到另一个select框中功能时遇到了一个问题&#xff0c;就是点击按钮时内容可以到另一个select框中&#xff0c;但是到了另一个select框中的内容却很快闪退回原来的select框中&#xff0c;代码如下&#xff1a; <select class"…

windows API 串口编程参考

*************************************************** 更多精彩&#xff0c;欢迎进入&#xff1a;http://shop115376623.taobao.com *************************************************** &#xff08;一&#xff09;Windows API串口通信编程概述 Windows环境下的串口编程与D…

jquery post php返回html,jquery ajax post 提交数据,返回的是当前网页的html?

代码如下用户名:密 码:$("#login_submit").bind("click",function(){var type "post";var url "index.php?madmin&cindex&acheckLogin";var formArrays $("#admin_form").serializeArray();var requestData …

[转]Android Studio系列教程六--Gradle多渠道打包

转自&#xff1a;http://www.stormzhang.com/devtools/2015/01/15/android-studio-tutorial6/ Android Studio系列教程六--Gradle多渠道打包 2015 年 01 月 15 日 devtools本文为个人原创&#xff0c;欢迎转载&#xff0c;但请务必在明显位置注明出处&#xff01; 由于国内Andr…

服务器上装filezilla server后,本地的ftp客户端连接不上去

公司一台服务器&#xff0c;上面装了filezilla server后&#xff0c;按平常配置好了&#xff0c;但是在本地用FTP客户端不管怎么连接都连接不上&#xff0c;本地FTP客户端总提示连接失败&#xff0c;远程filezilla server的界面也没有提示有人连接&#xff0c; 仔细看了一下&am…