UI2_ButtonChess
//
// AppDelegate.m
// UI2_ButtonChess
//
// Created by zhangxueming on 15/6/30.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "AppDelegate.h" @interface AppDelegate ()
{
UIButton *_lastBtn; //记录上次点击的btn
} @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[self showButtonChess];
self.window.rootViewController = nil;
self.window.backgroundColor = [UIColor whiteColor];
return YES;
} - (void)showButtonChess
{
NSArray *titles = @[@"車",@"马",@"象",@"王",@"后",@"象",@"马",@"車"]; CGFloat size = self.window.frame.size.width/8; for (int i=0; i<8; i++) {
for (int j=0; j<8; j++) {
UIView *view =[[UIView alloc] initWithFrame:
CGRectMake(j*size, 100+i*size, size, size)];
if ((i+j)%2) {
view.backgroundColor = [UIColor yellowColor];
}
else
{
view.backgroundColor= [UIColor cyanColor];
}
[self.window addSubview:view];
}
}
for (int i=0; i<8; i++) {
for (int j=0; j<8; j++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(j*size, 100+i*size, size, size);
if (i==0||i==7) {
[btn setTitle:titles[j] forState:UIControlStateNormal];
}
if (i==1||i==6) {
[btn setTitle:@"兵" forState:UIControlStateNormal];
} if (i==0||i==1) {
[btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
btn.titleLabel.font = [UIFont systemFontOfSize:30];
}
if (i==6||i==7) {
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
btn.titleLabel.font = [UIFont systemFontOfSize:30];
}
[btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:btn];
}
}
} - (void)btnClick:(UIButton *)btn
{
if (_lastBtn && ![btn.currentTitle length]) {
CGRect frame = _lastBtn.frame;
_lastBtn.frame = btn.frame;
btn.frame = frame;
_lastBtn = nil;
}
else if (!_lastBtn && btn.currentTitle.length)
{
_lastBtn = btn;
}
//[self.window bringSubviewToFront:btn];
}
UI2_ButtonChess的更多相关文章
随机推荐
- replace into
讨人喜欢的 MySQL replace into 用法(insert into 的增强版) 在向表中插入数据的时候,经常遇到这样的情况:1. 首先判断数据是否存在: 2. 如果不存在,则插入:3.如果 ...
- hdu5071 2014 Asia AnShan Regional Contest B Chat
模拟题: add的时候出现过的则不再添加 close的时候会影响到top rotate(Prior.Choose)的时候会影响到top /*============================== ...
- AJAX responseText vs responseXML
AJAX------>本质 Request/Response(Server)模式 response的形式 responseText--------->获得字符串形式的响应数据. ----- ...
- 【KPC】关于为什么不用Zepto而用JQuery
1.zepto在window phone手机上不是很兼容 2.JQuery的Deferred对象在zepto上不支持. 3.JQuery经过压缩,以及部分页面的使用,以及缓存,可以达到优化用户体验的效 ...
- IOS编程之相机和相册
概述 IOS设备中的相机和相册,是我们在项目开发中经常会使用到的多媒体元素,使用相机可以获得最新想要的照片,而使用相册则可以访问IOS设备中的图片资源 使用IOS设备中的相机/相册获得图片资源 是否允 ...
- 0c-39-ARC下单对象内存管理
1.ARC工作原理详述 ARC是Objective-C编译器的特性,而不是运行时特性或者垃圾回收机制,ARC所做的只不过是在代码编译时为你自动在合适的位置插入release或autorelease A ...
- 云服务器 ECS Linux 磁盘空间满(含 innode 满)问题排查方法
问题描述 在云服务器 ECS Linux 系统内创建文件时,出现类似如下空间不足提示: No space left on device … 问题原因 导致该问题的可能原因包括: 磁盘分区空间使用率达到 ...
- BIOS 深入学习 转
http://blog.csdn.net/lightseed/article/category/547391
- PHP自动分表程序
http://blog.zol.com.cn/2210/article_2209590.html /** * 分表程序 * * @author Shen Xi shen.xi@zol.com.cn ...
- jodd-StringTemplateParser使用
StringTemplateParser 时一个string模板的解析器.在string模板中定义类似jsp标签的宏. 在解析过程中,宏被对值替换,值通过自定义的MacroResolver解析得到. ...