一個(gè)可以快速集成的登錄頁(yè)面权纤,通過(guò)獲取驗(yàn)證碼登錄警医,以及登錄頁(yè)面的一個(gè)服務(wù)條款和隱私條款的跳轉(zhuǎn)!純代碼布局頁(yè)面贴捡,用到了sd_autolayout忽肛,以及自己寫的幾個(gè)封裝的類。
具體的實(shí)現(xiàn)方式直接看demo吧烂斋!
Simulator Screen Shot 2016年10月31日 下午3.46.40.png
幾個(gè)核心的代碼塊說(shuō)明一下
一個(gè)是驗(yàn)證碼倒計(jì)時(shí)這里
-(void)startTime{
self.isTimeing = YES;
__block int timeout = 60; //倒計(jì)時(shí)時(shí)間 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); //每秒執(zhí)行
dispatch_source_set_event_handler(_timer, ^{
if(timeout<=0){ //倒計(jì)時(shí)結(jié)束屹逛,關(guān)閉
dispatch_source_cancel(_timer);
dispatch_async(dispatch_get_main_queue(), ^{
//設(shè)置界面的按鈕顯示 根據(jù)自己需求設(shè)置
self.isTimeing = NO;
[VerCode setTitle:@"驗(yàn)證" 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(), ^{
//設(shè)置界面的按鈕顯示 根據(jù)自己需求設(shè)置
//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);
}
一個(gè)是服務(wù)條款和隱私條款的格式
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 = [@"點(diǎn)擊開始使用,即表示您同意<help>服務(wù)條款</help>及<settings>隱私條款</settings>" attributedStringWithStyleBook:style3];