一个可以快速集成的登录页面,通过获取验证码登录,以及登录页面的一个服务条款和隐私条款的跳转!纯代码布局页面,用到了sd_autolayout,以及自己写的几个封装的类。
具体的实现方式直接看demo吧!

几个核心的代码块说明一下
一个是验证码倒计时这里
-(void)startTime{
self.isTimeing = YES;
__block int timeout = 60; //倒计时时间 60s
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.isTimeing = NO;
[VerCode setTitle:@"验证" forState:UIControlStateNormal];
if (phoneNum.text.length > 0) {
[VerCode setBackgroundColor:key_BgColorF6E];
VerCode.enabled = YES;
}
});
}else{
int seconds = timeout % 61;
NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
dispatch_async(dispatch_get_main_queue(), ^{
//设置界面的按钮显示 根据自己需求设置
//NSLog(@"____%@",strTime);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[VerCode setTitle:[NSString stringWithFormat:@"%@s",strTime] forState:UIControlStateNormal];
[UIView commitAnimations];
VerCode.enabled = NO;
[VerCode setBackgroundColor:key_BgColorB2];
if (timeout == 50) {
canNotGetYZMLab.userInteractionEnabled = YES;
canNotGetYZMLab.textColor = key_BgColorF6E;
}
if (phoneNum.text.length == 0) {
timeout = 0;
passwordNum.text = @"";
}
});
timeout--;
}
});
dispatch_resume(_timer);
}
一个是服务条款和隐私条款的格式
float tw =[self widthForString:str fontSize:14 andHeight:20];
tw =([UIScreen mainScreen].bounds.size.width-tw)/2;
NSDictionary* style3 = @{@"body":[UIFont fontWithName:@"HelveticaNeue" size:12.0],
@"help":[WPAttributedStyleAction styledActionWithAction:^{
NSLog(@"Help action");
RemarkViewController *remark = [[RemarkViewController alloc]init];
remark.type =0;
[self.navigationController pushViewController:remark animated:YES];
}],
@"settings":[WPAttributedStyleAction styledActionWithAction:^{
NSLog(@"Settings action");
RemarkViewController *remark = [[RemarkViewController alloc]init];
remark.type = 1;
[self.navigationController pushViewController:remark animated:YES];
}],
@"link": key_BgColorF6E};
baoXian.textAlignment = NSTextAlignmentCenter;
baoXian.textColor = key_BgColor4D;
baoXian.attributedText = [@"点击开始使用,即表示您同意<help>服务条款</help>及<settings>隐私条款</settings>" attributedStringWithStyleBook:style3];
网友评论