iOS 简单的猜颜色游戏 界面设计的比较简单 - -
2015-07-31 13:54
363 查看
@interface ViewController ()
{
UILabel *jifen;
UILabel *label;
UIButton *button;
UIButton *button1;
NSTimer *timer;
NSTimer *timer1;
NSArray *color;
int showTime;
UILabel *NO1;
UILabel *show;
NSArray *anniu;
int b;
int index;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 开始按钮相关
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(150, 647, 80, 40);
button.center = CGPointMake(187.5, 627);
button.backgroundColor = [UIColor darkTextColor];
button.alpha = 0.6;
[button setTitle:@"开始" forState:UIControlStateNormal];
button.layer.cornerRadius = 4;
button.layer.masksToBounds = YES;
[button setTitleColor:[UIColor darkGrayColor] forState:UIControlStateHighlighted];
[button addTarget:self action:@selector(start) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
// 颜色按钮
anniu = @[@"橘红色",@"黑色",@"蓝色"];
for (int i = 0; i < 3; i ++) {
button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.frame =CGRectMake(61.5+(80+6)*i, 500, 80, 40);
button1.backgroundColor = [UIColor blackColor];
button1.alpha = 0.6;
button1.tag = 1000+i;
button1.layer.cornerRadius = 4;
button1.layer.masksToBounds = YES;
[button1 setTitle:anniu[i] forState:UIWindowLevelNormal];
[button1 setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
[button1 addTarget:self action:@selector(jifen:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button1];
}
color = @[
[UIColor orangeColor],
[UIColor blackColor],
[UIColor blueColor]
];
// 颜色显示框
NO1 =[[UILabel alloc]init];
NO1.backgroundColor = [UIColor lightGrayColor];
NO1.frame = CGRectMake(200, 400, 100, 40);
NO1.center = CGPointMake(187.5, 320);
NO1.layer.cornerRadius = 4;
NO1.layer.masksToBounds = YES;
[self.view addSubview:NO1];
// 计数器相关
showTime = 60;
label = [[UILabel alloc]init];
label.frame = CGRectMake(0, 0, 100, 100);
label.textAlignment = NSTextAlignmentCenter;
label.font =[UIFont systemFontOfSize:50];
label.center = CGPointMake(187.5, 250);
label.text = [@(showTime)stringValue];
[self.view addSubview:label];
// 定时器
timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(change) userInfo:nil repeats:YES];
timer.fireDate = [NSDate distantFuture];
// 定时器1
timer1 = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(turn) userInfo:nil repeats:YES];
timer1.fireDate = [NSDate distantFuture];
// 积分显示框
jifen = [[UILabel alloc]init];
jifen.frame = CGRectMake(0, 0, 120, 50);
jifen.center = CGPointMake(187.5, 130);
jifen.textAlignment = NSTextAlignmentCenter;
jifen.font = [UIFont systemFontOfSize:40];
jifen.text = [@(b)stringValue];
jifen.layer.cornerRadius = 4;
jifen.layer.masksToBounds = YES;
jifen.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:jifen];
}
// turn 方法
- (void)turn
{
int i = arc4random()%color.count;
index = i;
NO1.text = @"颜色";
NO1.textAlignment = NSTextAlignmentCenter;
NO1.textColor = color[i];
if (showTime == 0) {
timer1.fireDate = [NSDate distantFuture];
showTime = 60;
b = 0;
jifen.text = [@(b)stringValue];
NO1.textColor = [UIColor blackColor];
}
}
// 开始按钮
- (void)start
{
timer.fireDate = [NSDate distantPast];
timer1.fireDate = [NSDate distantPast];
}
// change 方法
-(void)change
{
showTime --;
if (showTime == 0) {
timer.fireDate = [NSDate distantFuture];
UIAlertView *tishi = [[UIAlertView alloc]initWithTitle:@"提示" message:@"时间到" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[tishi show];
}
label.text = [@(showTime)stringValue];
}
// 积分方法
- (void)jifen:(UIButton *)sender
{
if (sender.tag-1000 ==index) {
b += 5;
jifen.text = [@(b)stringValue];
}else{
b -=5;
jifen.text = [@(b)stringValue];
}
}
{
UILabel *jifen;
UILabel *label;
UIButton *button;
UIButton *button1;
NSTimer *timer;
NSTimer *timer1;
NSArray *color;
int showTime;
UILabel *NO1;
UILabel *show;
NSArray *anniu;
int b;
int index;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 开始按钮相关
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(150, 647, 80, 40);
button.center = CGPointMake(187.5, 627);
button.backgroundColor = [UIColor darkTextColor];
button.alpha = 0.6;
[button setTitle:@"开始" forState:UIControlStateNormal];
button.layer.cornerRadius = 4;
button.layer.masksToBounds = YES;
[button setTitleColor:[UIColor darkGrayColor] forState:UIControlStateHighlighted];
[button addTarget:self action:@selector(start) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
// 颜色按钮
anniu = @[@"橘红色",@"黑色",@"蓝色"];
for (int i = 0; i < 3; i ++) {
button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.frame =CGRectMake(61.5+(80+6)*i, 500, 80, 40);
button1.backgroundColor = [UIColor blackColor];
button1.alpha = 0.6;
button1.tag = 1000+i;
button1.layer.cornerRadius = 4;
button1.layer.masksToBounds = YES;
[button1 setTitle:anniu[i] forState:UIWindowLevelNormal];
[button1 setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
[button1 addTarget:self action:@selector(jifen:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button1];
}
color = @[
[UIColor orangeColor],
[UIColor blackColor],
[UIColor blueColor]
];
// 颜色显示框
NO1 =[[UILabel alloc]init];
NO1.backgroundColor = [UIColor lightGrayColor];
NO1.frame = CGRectMake(200, 400, 100, 40);
NO1.center = CGPointMake(187.5, 320);
NO1.layer.cornerRadius = 4;
NO1.layer.masksToBounds = YES;
[self.view addSubview:NO1];
// 计数器相关
showTime = 60;
label = [[UILabel alloc]init];
label.frame = CGRectMake(0, 0, 100, 100);
label.textAlignment = NSTextAlignmentCenter;
label.font =[UIFont systemFontOfSize:50];
label.center = CGPointMake(187.5, 250);
label.text = [@(showTime)stringValue];
[self.view addSubview:label];
// 定时器
timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(change) userInfo:nil repeats:YES];
timer.fireDate = [NSDate distantFuture];
// 定时器1
timer1 = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(turn) userInfo:nil repeats:YES];
timer1.fireDate = [NSDate distantFuture];
// 积分显示框
jifen = [[UILabel alloc]init];
jifen.frame = CGRectMake(0, 0, 120, 50);
jifen.center = CGPointMake(187.5, 130);
jifen.textAlignment = NSTextAlignmentCenter;
jifen.font = [UIFont systemFontOfSize:40];
jifen.text = [@(b)stringValue];
jifen.layer.cornerRadius = 4;
jifen.layer.masksToBounds = YES;
jifen.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:jifen];
}
// turn 方法
- (void)turn
{
int i = arc4random()%color.count;
index = i;
NO1.text = @"颜色";
NO1.textAlignment = NSTextAlignmentCenter;
NO1.textColor = color[i];
if (showTime == 0) {
timer1.fireDate = [NSDate distantFuture];
showTime = 60;
b = 0;
jifen.text = [@(b)stringValue];
NO1.textColor = [UIColor blackColor];
}
}
// 开始按钮
- (void)start
{
timer.fireDate = [NSDate distantPast];
timer1.fireDate = [NSDate distantPast];
}
// change 方法
-(void)change
{
showTime --;
if (showTime == 0) {
timer.fireDate = [NSDate distantFuture];
UIAlertView *tishi = [[UIAlertView alloc]initWithTitle:@"提示" message:@"时间到" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[tishi show];
}
label.text = [@(showTime)stringValue];
}
// 积分方法
- (void)jifen:(UIButton *)sender
{
if (sender.tag-1000 ==index) {
b += 5;
jifen.text = [@(b)stringValue];
}else{
b -=5;
jifen.text = [@(b)stringValue];
}
}
相关文章推荐
- iOS8新特性扩展(Extension)应用之四——自定义键盘控件
- IOS:ios最简单的控件练习
- ios NSNotificationCenter 的简单使用
- iOS8 iPAD上弹出所谓的ActionSheet
- iOS 如何获取屏幕大小
- iOS应用内付费(IAP)开发步骤列表
- 【转】如何入门iOS开发
- iOS画线
- iOS提交后申请加急审核
- iOS CGRectInset,CGRectOffset
- ios命名规范
- iOS- 如何集成支付宝
- iOS storyboard 添加Entry point
- iOS 利用AVPlayer创建视频播放器
- iOS开发小技巧
- ios开发小技巧
- IOS图片缩放
- iOS字符串的国际化图解
- iOS开发——创建你自己的Framework
- iOS frame bouns 区别