Last active
August 29, 2015 14:09
-
-
Save roodkcab/f10c7500ebeaf8aee7ed to your computer and use it in GitHub Desktop.
发送短信验证码按钮点击倒数计时
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| send.rac_command = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) { | |
| NSDate *start = [NSDate date]; | |
| [send setAttributedTitle:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%f s", 5.f] | |
| attributes:@{ | |
| NSFontAttributeName:[UIFont fontWithName:@"STHeitiSC-Medium" size:16], | |
| NSForegroundColorAttributeName:[UIColor blackColor] | |
| }] forState:UIControlStateNormal]; | |
| return [send rac_liftSelector:@selector(setAttributedTitle:forState:) | |
| withSignals: | |
| [[[[RACSignal interval:1 onScheduler:[RACScheduler currentScheduler]] | |
| startWith:start] | |
| takeWhileBlock:^BOOL(id x) { | |
| return ![send.titleLabel.attributedText.string isEqualToString:@"测试"]; | |
| }] | |
| map:^id (NSDate *value) { | |
| NSTimeInterval timer = [[NSDate date] timeIntervalSinceDate:start]; | |
| if (timer >= 5) { | |
| return [[NSAttributedString alloc] initWithString:@"测试" | |
| attributes:@{ | |
| NSFontAttributeName:[UIFont fontWithName:@"STHeitiSC-Medium" size:16], | |
| NSForegroundColorAttributeName:[UIColor blackColor] | |
| }]; | |
| } | |
| return [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%d s", (int)ceil(5-timer)] | |
| attributes:@{ | |
| NSFontAttributeName:[UIFont fontWithName:@"STHeitiSC-Medium" size:16], | |
| NSForegroundColorAttributeName:[UIColor blackColor] | |
| }]; | |
| }], | |
| [RACSignal return:@(UIControlStateNormal)], | |
| nil]; | |
| }]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment