标签:
#import "ViewController.h"
@interface ViewController ()
{
NSMutableArray *nameList;
UILabel *label;
NSTimer *timer;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self loadData];
self.view.backgroundColor = [UIColor grayColor];
label = [[UILabel alloc]initWithFrame:CGRectMake(50, 200, 275, 50)];
label.text = @"不会是我吧";
label.textAlignment = NSTextAlignmentCenter;
label.font = [UIFont systemFontOfSize:30];
label.textColor = [UIColor orangeColor];
label.backgroundColor = [UIColor clearColor];
[self.view addSubview:label];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(150, 500, 100, 100);
[self.view addSubview:button];
[button setTitle:@"点我啊" forState:UIControlStateNormal];
button.backgroundColor = [UIColor redColor];
button.layer.cornerRadius = 50;
button.layer.masksToBounds = YES;
button.showsTouchWhenHighlighted = YES;
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button addTarget:self action:@selector(push:) forControlEvents:UIControlEventTouchUpInside];
timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(loadData) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop ]addTimer:timer forMode:NSDefaultRunLoopMode];
timer.fireDate = [NSDate distantFuture];
}
- (void)loadData
{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
nameList = [NSMutableArray arrayWithObjects:@"a",@"b",@"c",@"d",@"e",@"f",@"g俊",@"f",@"gd",@"fv",@"sd",@"f",@"sdf",@"4t",@"i红",@"k",@"u",@"i海",@"ijk",@"k",@"i林",@"杨小平",@"i均",@"ui飞",@"i宽富",@"i旺",@"e浩",@"i诚",@"i文兴",@"i水",@"i波",@"tu金奎",@"i",@"王e",@"5j来",@"l康",@"i8黔",@"k.意",@";龙",@u波",@"ol忠6华",@"y涛", nil];
[userDefaults setObject:nameList forKey:@"nameList"];
[userDefaults synchronize];
[userDefaults objectForKey:@"nameList"];
int arcNumber = arc4random()%nameList.count;
label.text = nameList[arcNumber];
}
- (void)push:(UIButton *)sender
{
if (sender.selected !=YES ) {
label.textColor = [UIColor clearColor];
[sender setTitle:@"暂停" forState:UIControlStateNormal];
// [nameList removeObject:label.text];
timer.fireDate = [NSDate distantPast];
sender.selected = YES;
}else{
timer.fireDate = [NSDate distantFuture];
label.textColor = [UIColor blackColor];
[sender setTitle:@"点我啊" forState:UIControlStateNormal];
sender.selected = NO;
}
}
- (void)showAlertMessage:(NSString *)message
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"真的是你" message:message delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
@end
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/jzq_sir/article/details/47205987