UITouchView实现关灯游戏
来源:互联网 发布:android 7.0 数据库 编辑:程序博客网 时间:2024/06/11 21:12
MainViewControl.m
#import "MainViewController.h"#import "TouchView.h"@interface MainViewController ()@end@implementation MainViewController- (void) dealloc{ [super dealloc];}- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self;}- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view. TouchView * view = [[TouchView alloc] initWithFrame:CGRectMake(10, 20, 300, 440)]; [view setBackgroundColor:[UIColor blueColor]]; [self.view addSubview:view]; [view release];}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
TouchView.m
#import "TouchView.h"@implementation TouchView- (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { // Initialization code [self creatButton]; } return self;}- (void)creatButton{ int tag = 101; for (int i = 0; i < 8; i++) { for (int j = 0; j < 6; j++) { UIButton * button = [[UIButton alloc] initWithFrame:CGRectMake(5+(50*j), 20+(i*50), 40, 40)]; [button setBackgroundColor:[UIColor yellowColor]]; [button setTag:tag++]; [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:button]; [button release]; tag++; } tag += 5; }}- (void)buttonAction:(id)sender{ UIButton * button = (UIButton *)sender; UIButton * leftButton = (UIButton *)[self viewWithTag:button.tag - 1]; UIButton * rightButton = (UIButton *)[self viewWithTag:button.tag + 1]; UIButton * upButton = (UIButton *)[self viewWithTag:button.tag - 6]; UIButton * downButton = (UIButton *)[self viewWithTag:button.tag + 6]; if (button.backgroundColor == [UIColor yellowColor]) { [button setBackgroundColor:[UIColor magentaColor]]; }else{ [button setBackgroundColor:[UIColor yellowColor]]; } if (upButton.backgroundColor == [UIColor yellowColor]) { [upButton setBackgroundColor:[UIColor magentaColor]]; }else{ [upButton setBackgroundColor:[UIColor yellowColor]]; } if (downButton.backgroundColor == [UIColor yellowColor]) { [downButton setBackgroundColor:[UIColor magentaColor]]; }else{ [downButton setBackgroundColor:[UIColor yellowColor]]; } if (leftButton.backgroundColor == [UIColor yellowColor]) { [leftButton setBackgroundColor:[UIColor magentaColor]]; }else{ [leftButton setBackgroundColor:[UIColor yellowColor]]; } if (rightButton.backgroundColor == [UIColor yellowColor]) { [rightButton setBackgroundColor:[UIColor magentaColor]]; }else{ [rightButton setBackgroundColor:[UIColor yellowColor]]; } }@end
0 0
- UITouchView实现关灯游戏
- 关灯游戏的实现
- 关灯游戏的实现
- UI游戏实现 关灯游戏
- UI, 关灯游戏的实现
- 关灯游戏
- 关灯游戏
- 关灯游戏
- 关灯游戏
- 关灯游戏
- 关灯游戏
- 关灯游戏
- 关灯游戏
- 关灯游戏
- 通过target-action 实现关灯游戏
- iOS实现简单的关灯游戏
- iOS关灯游戏AI的设计和实现
- IOS 关灯游戏
- POJ1182
- 一位ACM过来人的心得
- amber
- 第一次来报到一下
- Oracle 10g创建表空间的完整步骤详解
- UITouchView实现关灯游戏
- Eclipse怎么设置自动补齐以及怎么格式化代码
- String、StringBuffer、StringBuilder差异“详”解
- 变量的作用域--js闭包
- 明天休息去那里玩才好
- Excel VBA 学习站点
- 使用递归解决一种约瑟夫问题
- AT命令详解
- 国内一款仅需150内存的开源JAVA企业网站系统-MiinE