博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
随机数
阅读量:4450 次
发布时间:2019-06-07

本文共 1584 字,大约阅读时间需要 5 分钟。

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

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 *)sender22 {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秒执行一次timeRun29         30     } else {31         32         [_timer invalidate];33         //关闭时间器34     }35 }36 37 - (void)timeRun38 {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找view44     45     label.text = [NSString stringWithFormat:@"%d%02d",row,num];46 }

 

转载于:https://www.cnblogs.com/Angelone/p/4384817.html

你可能感兴趣的文章
java面试题(基础+非基础)[不定期更新]
查看>>
程序员玩转投资 - 基金定投的7个缺点和误区
查看>>
使用 WordPress 的导航菜单
查看>>
input只能输入数字和小数点,并且只能保留小数点后两位 - CSDN博客
查看>>
js 不固定传参
查看>>
Linux信号
查看>>
iOS中的NSdate
查看>>
Netty--数据通信和心跳检测
查看>>
liunx环境下安装mysql5.7及以上版本
查看>>
远程调试UWP遇到新错误Could not generate the root folder for app package ......
查看>>
eclipse配置maven
查看>>
CentOS Docker 安装
查看>>
[原创]java WEB学习笔记13:JSP介绍(背景,特点,原理)
查看>>
[原创]java WEB学习笔记54:Struts2学习之路--- 编写Struts2 的第一个程序,HelloWord,简述 package ,action,result...
查看>>
[原创]java WEB学习笔记105:Spring学习---AOP介绍,相关概念,使用AOP,利用 方法签名 编写 AspectJ 切入点表达式...
查看>>
了解JS模块规范:AMD,CMD,CommonJS
查看>>
九度OJ 1500 出操队形 -- 动态规划(最长上升子序列)
查看>>
poj 1466(最大独力集)
查看>>
poj 3308
查看>>
数据访问----事务实例
查看>>