• 随机数


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

     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 }
  • 相关阅读:
    Inline Hook 钩子编写技巧
    FPS 游戏实现D3D透视 (API Hook)
    FPS 游戏实现GDI透视 (三角函数)
    X86驱动:恢复SSDT内核钩子
    X86驱动:挂接SSDT内核钩子
    VS2013+WDK8.1 驱动开发环境配置
    C/C++ 语言之反汇编揭秘:目录
    WinRAR 去广告的姿势
    C/C++ 实现反调试的手段
    springboot项目部署到独立tomcat的爬坑集锦
  • 原文地址:https://www.cnblogs.com/Angelone/p/4384817.html
Copyright © 2020-2023  润新知