zoukankan      html  css  js  c++  java
  • 利用定时器展示动态文字

     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



  • 相关阅读:
    xshel链接linuxl安装nginx
    nginx学习笔记
    sweiper做一个tab切换
    bootstrap中tab切换的使用
    pc页面自动缩放到手机端
    日程表
    页面嵌套iframe时,怎样让iframe高度根据自身内容高度自适应
    mysql5.7版本以上下载安装
    电脑快捷键操作汇总
    关于.eslintrc.js代码检测的一些配置
  • 原文地址:https://www.cnblogs.com/shen5214444887/p/4877529.html
Copyright © 2011-2022 走看看