iOS开发之 简易随机点名册的设计
来源:互联网 发布:美国网络空军 编辑:程序博客网 时间:2024/06/07 06:21
效果图如下:
先看看定义的全局变量:
<span style="font-size:14px;color:#666666;">{ NSMutableArray *arrName;// 后台所用名字的数组 UILabel *label ;// 显示抽到的名字的label NSTimer *timer;// 在点击开始按钮后,定时器开始运行 UIButton *button;// 开始的按钮}</span>
<span style="font-size:18px;"> </span><span style="font-size:14px;">// 后台所用名字的数组 arrName = [NSMutableArray arrayWithObjects:@"刘亭均",@"黄方果",@"杨鹏飞",@"周总", nil]; // 开始的按钮 self.view.backgroundColor = [UIColor grayColor]; button = [UIButton buttonWithType:UIButtonTypeCustom]; button.backgroundColor = [UIColor greenColor]; button.frame = CGRectMake(120, 500, 100, 35); [button setTitle:@"开始" forState:UIControlStateNormal]; button.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2+100); [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted]; [self.view addSubview:button]; [button addTarget:self action:@selector(find) forControlEvents:UIControlEventTouchUpInside]; // 在点击开始按钮后,定时器开始运行 timer = [NSTimer timerWithTimeInterval:0.05 target:self selector:@selector(zhuan) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop]addTimer:timer forMode:NSDefaultRunLoopMode]; timer.fireDate = [NSDate distantFuture ]; // 显示抽到的名字的label label = [[UILabel alloc]init]; label.backgroundColor = [UIColor whiteColor]; label.frame = CGRectMake(0, 0, 150, 35); label.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2-100); label.text = @"猜猜点到谁"; label.textColor = [UIColor blackColor]; label.textAlignment = NSTextAlignmentCenter; [self.view addSubview:label];}#pragma mark -----------设置button在点击的时候开始或者暂停-------------- (void)find{ if (button.selected != YES) { button.selected = YES; [button setTitle:@"暂停" forState:UIControlStateNormal]; [self start]; }else{ button.selected = NO; [button setTitle:@"开始" forState:UIControlStateNormal]; [self stop]; }}#pragma mark ---------点击开始按钮后,展示的label框展示随机晃动的名字------------- (void)zhuan{ int i = arc4random()%arrName.count; label.text = [NSString stringWithFormat:@"中奖者是:%@",arrName[i]];}- (void)start{ timer.fireDate = [NSDate distantPast];}- (void)stop{ timer.fireDate = [NSDate distantFuture]; NSString *s = label.text; if(arrName.count >1) { [arrName removeObject:s]; } for (NSString *name in arrName) { NSLog(@"%@",name); }}</span>
我们所用得名字数组是可变的,所以说我们只要改变我们自己的名字数组,就成了一个简单的点名器了。
0 0
- iOS开发之 简易随机点名册的设计
- iOS开发之简易时钟的制作
- iOS开发之MediaPlayer框架的简易使用
- iOS开发之产生随机浮点数
- 【iOS开发】简易加法计算器的实现
- iOS开发:简易天气预报
- iOS开发之把数组中的元素进行随机排序、随机数产生的几种方法
- iOS开发之设计模式
- iOS开发之设计模式
- 基于stratus +flex+MySQL的简易在线随机视频聊天室的开发
- 基于stratus +flex+MySQL的简易在线随机视频聊天室的开发
- IOS 之 界面开发设计的一些资料
- ios之开发中常用的设计模式介绍
- IOS开发之微博的设计与实现
- iOS 开发之IPad的设计与实现
- ios开发之公交卡系统的设计与实现
- ios开发之电子优惠券的设计与实现
- ios开发之自动售货机的设计与实现
- js中的几种继承方式
- 5.Swift 跳转和动画
- 20151006考试总结
- test
- C++各种崩溃分析
- iOS开发之 简易随机点名册的设计
- Mac删除所有DS_store文件
- mysql子查询优化
- 0 /空/ 空数组
- trace.log20151006---PropertyUtils.describe
- C++实现单链表
- CentOS 7 配置squid 透明代理(测试笔记)
- C++11 lambda 表达式
- 【leetcode】Intersection of Two Linked Lists