首页 > 其他 > 详细

利用定时器展示动态文字

时间:2015-10-14 15:58:00      阅读:345      评论:0      收藏:0      [点我收藏+]

 

 1 #import "ViewController.h"
 2 
 3 static NSInteger count = 0;
 4 
 5 @interface ViewController ()
 6 
 7 @property (weak, nonatomic) IBOutlet UILabel *label;
 8 
 9 @property (nonatomic, strong)NSArray *array;
10 /** 添加定时器 */
11 @property (nonatomic, strong) NSTimer *time;
12 
13 @end
14 
15 @implementation ViewController
16 
17 - (NSArray *)array
18 {
19     if(!_array)
20     {
21         _array = [NSArray arrayWithObjects:@"1...",@"2....",@"3.....",@"4......", nil];
22     }
23     return _array;
24 }
25 
26 - (void)viewDidLoad {
27     [super viewDidLoad];
28     
29     self.time = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(runLabel) userInfo:nil repeats:YES];
30     [self.time fire]; // 立即触发定时器
31 //    [time setFireDate:[NSDate distantPast]]; // 开启定时器
32 //    [time setFireDate:[NSDate distantFuture]]; // 暂停定时器
33 }
34 
35 - (void)runLabel
36 {
37     self.label.text = self.array[count++ % self.array.count];
38 }
39 
40 /** 移除定时器 */
41 - (void)removeTimer
42 { // 定时器一旦被停止,不会重新开始,要被移除。
43     [self.time invalidate];
44     self.time = nil;
45 }
46 - (void)didReceiveMemoryWarning {
47     [super didReceiveMemoryWarning];
48     // Dispose of any resources that can be recreated.
49 }
50 
51 @end



利用定时器展示动态文字

原文:http://www.cnblogs.com/shen5214444887/p/4877529.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!