码迷,mamicode.com
首页 > 其他好文 > 详细

2016-01-07 定时器

时间:2016-01-07 18:01:07      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:

#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

2016-01-07 定时器

标签:

原文地址:http://www.cnblogs.com/gzz2016/p/5110686.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!