zoukankan      html  css  js  c++  java
  • 随机数

        一个小小的随机数工具。。。。。。。

     1 self.view.backgroundColor = [UIColor yellowColor];
     2     
     3     UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(40, 40, 240, 60)];
     4     label.font = [UIFont boldSystemFontOfSize:30];
     5     label.text = @"点击开始随机";
     6     label.backgroundColor = [UIColor grayColor];
     7     label.textAlignment = NSTextAlignmentCenter;
     8     label.tag = 1;
     9     [self.view addSubview:label];
    10     [label release];
    11     
    12     UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    13     btn.frame = CGRectMake(120, 180, 80, 40);
    14     btn.backgroundColor = [UIColor grayColor];
    15     [btn setTitle:@"开始" forState:UIControlStateNormal];
    16     [btn setTitle:@"停止" forState:UIControlStateSelected];
    17     [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    18     [self.view addSubview:btn];
    19 }
    20 
    21 - (void)btnClick:(UIButton *)sender
    22 {
    23     sender.selected = !sender.selected;
    24     
    25     if (sender.selected) {
    26         
    27         _timer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(timeRun) userInfo:nil repeats:YES];
    28         //启动时间器,让self每隔0.01秒执行一次timeRun
    29         
    30     } else {
    31         
    32         [_timer invalidate];
    33         //关闭时间器
    34     }
    35 }
    36 
    37 - (void)timeRun
    38 {
    39     int row = arc4random_uniform(8)+1;
    40     int num = arc4random_uniform(11)+1;
    41     
    42     UILabel *label = (UILabel *)[self.view viewWithTag:1];
    43     //通过tag找view
    44     
    45     label.text = [NSString stringWithFormat:@"%d%02d",row,num];
    46 }
  • 相关阅读:
    Java监听器Listener使用详解
    浮点数运算
    变量
    java For 循环 运行顺序
    java ++运算
    一些硬件厂商的MAC号
    c# 双问号运算
    SQL Server 触发器
    微软企业库Microsoft Enterprise Library的相关文章链接
    关于ligerUi的ligertree的初始化默认选中指定项目的方法
  • 原文地址:https://www.cnblogs.com/Angelone/p/4384817.html
Copyright © 2011-2022 走看看