Author: Loving_ios
Reprint please indicate the source: http://blog.csdn.net/loving_ios/article/details/50786890
Download Countdown button Jkcountdownbutton Code transfer door
Jkcountdownbutton, the implementation of the iOS Countdown button, often used for registration, such as sending verification code when the countdown operation.
Here's how to use it:
Code method Creation:
Jkcountdownbutton *button = [Jkcountdownbutton buttonwithtype:uibuttontypecustom];
Button.frame = CGRectMake (M, M, MB);
[Button settitle:@ "Get Authentication Code" Forstate:uicontrolstatenormal];
Button.backgroundcolor = [Uicolor bluecolor];
[Self.view Addsubview:button];
[Button addtouchehandler:^ (Jkcountdownbutton*sender, nsinteger tag) {
sender.enabled = NO;
[Sender startwithsecond:10.0];
[Sender didchange:^nsstring * (Jkcountdownbutton *countdownbutton,int second) {
nsstring *title = [NSString stringwithformat:@ "%d seconds remaining", second];
return title;
}];
[Sender didfinished:^nsstring * (Jkcountdownbutton *countdownbutton, int second) {
countdownbutton.enabled = YES;< C13/>return @ "Click Re-Acquire";
}]
;
Create with a drag control: first you want button to inherit Jkcountdownbutton class, type set to Custom
@property (Weak, nonatomic) Iboutlet Jkcountdownbutton *button;
-(Ibaction) Countdown: (jkcountdownbutton*) Sender {
sender.enabled = NO;
Button type is set to custom otherwise it will flicker
[sender startwithsecond:10.0];
[Sender didchange:^nsstring * (Jkcountdownbutton *countdownbutton,int second) {
nsstring *title = [NSString stringwithformat:@ "%d seconds remaining", second];
return title;
}];
[Sender didfinished:^nsstring * (Jkcountdownbutton *countdownbutton, int second) {
countdownbutton.enabled = YES;< C10/>return @ "Click Re-Acquire";}
]
Effect Chart: