2016-01-07 定时器
2016-01-07 17:42
197 查看
#import "timerViewController.h"
@interface timerViewController ()
{
NSTimer *timerTaks;
int CountdownInt;
UILabel *labCountdown;
}
@end
@implementation timerViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor=[UIColor whiteColor];
CountdownInt=0;
labCountdown=[[UILabel alloc]initWithFrame:CGRectMake(30, 100, 50, 40)];
labCountdown.backgroundColor=[UIColor yellowColor];
labCountdown.textColor=[UIColor redColor];
[self.view addSubview:labCountdown];
timerTaks = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(CountdownTimeer) userInfo:nil repeats:YES];
}
-(void)CountdownTimeer
{
CountdownInt++;
if (CountdownInt==60) {
[timerTaks invalidate];
labCountdown.hidden = YES;
CountdownInt = 0;
}else
{
labCountdown.text = [NSString stringWithFormat:@"%ds",60-CountdownInt];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
@interface timerViewController ()
{
NSTimer *timerTaks;
int CountdownInt;
UILabel *labCountdown;
}
@end
@implementation timerViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor=[UIColor whiteColor];
CountdownInt=0;
labCountdown=[[UILabel alloc]initWithFrame:CGRectMake(30, 100, 50, 40)];
labCountdown.backgroundColor=[UIColor yellowColor];
labCountdown.textColor=[UIColor redColor];
[self.view addSubview:labCountdown];
timerTaks = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(CountdownTimeer) userInfo:nil repeats:YES];
}
-(void)CountdownTimeer
{
CountdownInt++;
if (CountdownInt==60) {
[timerTaks invalidate];
labCountdown.hidden = YES;
CountdownInt = 0;
}else
{
labCountdown.text = [NSString stringWithFormat:@"%ds",60-CountdownInt];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
相关文章推荐
- SQL Server 2012 使用警报调度数据库作业通知操作员
- GCD (Grand Central Dispatch)
- Scala数据集操作
- There is no default constructor available in xxx错误引发
- Android开源项目分类汇总
- sqlplus
- Oracle的rowid
- python运算符
- 读取本地路径转换成bitmap的方法,以及避免outmemory
- MapReduce概念
- Eclipse中SVN的安装步骤(两种)和使用方法
- Mybatis关联查询一对一和一对多的实现
- Android中BroadcastReceiver的介绍
- C#实现在winfrom程序中下载文件
- 面向对象思想设计原则及常见设计模式
- Repmat:Replicate and tile an array
- 多线程(二)
- 其它途径启动本地Activity
- mysql prepare 存储过程使用
- iOS开发官方文档