此图为在其初始状态下的状态,通过点击start 按钮实现其功能,主要用到了计时器这个方法
[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];// 创建点击按钮的绑定事件
[self.view addSubview:button];
}
- (void)click:(UIButton *)button //判断按钮是否被点击
{
button.selected = !button.selected;
if (button.selected == YES) {
self.time = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(click2) userInfo:nil repeats:YES]; // 用NSTimer 方法实现其循环执行其要执行的内容
} else {
[self.time invalidate];
}
}
- (void)click2
{
NSMutableArray *array = [NSMutableArray arrayWithObjects:@"王奇", @"李校州", @"潘小龙", @"付饶", @"杨烁", @"张旭", @"王德民", @"孟令学", @"宋爽", @"徐会玲", nil]; //对所用的存储的数据放在字典里
UIButton *button = (UIButton *)[self.view viewWithTag:200];//找到Button对象对应的视图
static int i = 1;
if (i >= [array count]) {
i = 0;
}
[button setTitle:[array objectAtIndex:i++] forState:UIControlStateNormal]; //对其Button进行赋值
}