短信倒计时和欢迎界面的Demo

1.短信倒计时的方法使用的是一个多线程的的倒计时的处理方法:(采用的是MOB的短信的哪个三方库的东西)

__blockinttimeout =60;//倒计时时间修改关键字加__block

dispatch_queue_tqueue =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.codeBtnsetTitle:@"重新发送"forState:UIControlStateNormal];

self.codeBtn.userInteractionEnabled=YES;

});

}else{

intseconds = timeout %69;

NSString*strTime = [NSStringstringWithFormat:@"%.2d", seconds];

dispatch_async(dispatch_get_main_queue(), ^{

[self.codeBtnsetTitle:[NSStringstringWithFormat:@"%@s",strTime]forState:UIControlStateNormal];

[self.codeBtnsetTitleColor:GRAYCOLORforState:UIControlStateNormal];

self.codeBtn.userInteractionEnabled=NO;

});

timeout--;

}

});

dispatch_resume(_timer);

[SMSSDKgetVerificationCodeByMethod:SMSGetCodeMethodSMSphoneNumber:self.phoneTF.textzone:@"86"customIdentifier:nilresult:^(NSError*error) {

if(!error) {

DLog(@"获取验证码成功");

}else{

NSString*errStr = [[NSStringalloc]init];

errStr = error.userInfo[@"getVerificationCode"];

[selfshowTips:errStrToView:self];

}

}];

得到验证码之后的话要验证下验证码是否是确定的方法-==>

[SMSSDKcommitVerificationCode:self.codeTF.textphoneNumber:self.phoneTF.textzone:@"86"result:^(NSError*error) {

if(!error) {

NSLog(@"验证成功");

//获取短信的东西

[selfcheckPhone];

}else{

NSLog(@"错误信息:%@",error);

}

}];

到这里就可以直接使用了

2.欢迎界面的Demo代码:

- (void)viewDidLoad {

[superviewDidLoad];

//setupScrollview

[selfsetupScollView];

//setupPageContol

[selfsetupPageControl];

//隐藏navbar

self.navigationController.navigationBarHidden=YES;

}

-(void)setupScollView{

UIScrollView*scrollview = [[UIScrollViewalloc]init];

scrollview.frame=self.view.bounds;

scrollview.delegate=self;

[self.viewaddSubview:scrollview];

//添加图片

CGFloatimageW = scrollview.width;

CGFloatimageH = scrollview.height;

for(inti =0; i

UIImageView*imageView = [[UIImageViewalloc]init];

NSString*name = [NSStringstringWithFormat:@"welcome%d",i+1];

imageView.image= [UIImageimageNamed:name];

[scrollviewaddSubview:imageView];

UIButton*button = [[UIButtonalloc]init];

button.frame=CGRectMake(self.view.width*0.82,10,40,20);

[buttonsetTitle:@"跳过"forState:UIControlStateNormal];

[buttonaddTarget:selfaction:@selector(startExperience)forControlEvents:UIControlEventTouchUpInside];

button.titleLabel.font= [UIFontsystemFontOfSize:12];

button.alpha=0.6;

button.backgroundColor= [UIColorlightGrayColor];

imageView.userInteractionEnabled=YES;

[imageViewaddSubview:button];

//给最后一个imageview添加一个图片

if(i ==EVNewFeatureImageVieCount-1) {

[selfsetupLastImageView:imageView];

[buttonremoveFromSuperview];

}

imageView.y=0;

imageView.width= imageW;

imageView.height= imageH;

imageView.x= i * imageW;

}

//设置属性

scrollview.contentSize=CGSizeMake(EVNewFeatureImageVieCount* imageW,0);

scrollview.pagingEnabled=YES;

scrollview.showsHorizontalScrollIndicator=NO;

scrollview.backgroundColor=RGBCOLOR(246,246,246);

}

-(void)setupPageControl{

UIPageControl*pageControl = [[UIPageControlalloc]init];

pageControl.numberOfPages=EVNewFeatureImageVieCount;

pageControl.centerX=self.view.width*0.5;

pageControl.centerY=self.view.height-30;

pageControl.currentPageIndicatorTintColor= [UIColorredColor];

pageControl.pageIndicatorTintColor= [UIColorlightGrayColor];

[self.viewaddSubview:pageControl];

self.pageControl= pageControl;

}

//给加上一个image

-(void)setupLastImageView:(UIImageView*)imageView{

imageView.userInteractionEnabled=YES;

//添加开始按钮了

[selfsetupStartButton:imageView];

}

-(void)setupStartButton:(UIImageView*)imageView{

UIButton*startButton = [[UIButtonalloc]init];

[imageViewaddSubview:startButton];

startButton.backgroundColor=RGBCOLOR(2,152,221);

//设置frame

startButton.size=CGSizeMake(70,25);

startButton.centerX=self.view.width*0.5;

startButton.centerY=self.view.height*0.86;

//设置按钮兴致,描边

startButton.layer.cornerRadius=10/3;

startButton.layer.borderColor= [[UIColorwhiteColor]CGColor];

startButton.layer.borderWidth=1.2;

startButton.layer.masksToBounds=YES;

//设置文字

[startButtonsetTitle:@"开始体验"forState:UIControlStateNormal];

startButton.titleLabel.font= [UIFontsystemFontOfSize:13];

[startButtonsetTitleColor:[UIColorwhiteColor]forState:UIControlStateNormal];

[startButtonaddTarget:selfaction:@selector(startExperience)forControlEvents:UIControlEventTouchUpInside];

}

//开始广告页

-(void)startExperience{

ZFLoginViewController*loginVC = [[ZFLoginViewControlleralloc]init];

[self.navigationControllerpushViewController:loginVCanimated:YES];

//第一次的东西

BOOLnotFrist =YES;

[[NSUserDefaultsstandardUserDefaults]setBool:notFristforKey:@"isFirst"];

[[NSUserDefaultsstandardUserDefaults]synchronize];

}

#pragma mark - UIScrollviewDelegate

-(void)scrollViewDidScroll:(UIScrollView*)scrollView{

//获取页码

CGFloatdoublePage = scrollView.contentOffset.x/scrollView.width;

intintPage = (int)(doublePage +0.5);

//设置页码

self.pageControl.currentPage= intPage;

}

3.广告界面Demo代码:

待续。。。。。。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容