//
// 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的更多相关文章

随机推荐

  1. Struts2中属性驱动与模型驱动

    属性驱动: 1.概念 能够利用属性驱动获取页面表单元素的内容 2.步骤 1.在action中声明属性,属性的名称和页面元素中name属性的值保持一致 2.action中的属性必须有set和get方法 ...

  2. 手把手让你爱上Android sdk自带“9妹”(9patch 工具)

    前几天群成员讨论过关于9patch的工具[我比较喜欢喊它9妹子,西西(*^_^*)].然后研究了一下,比较简单但是很实用的一个Android sdk 自带工具.这里给大家做一个分享下经验! 1.什么是 ...

  3. ios开发——实用技术篇&数据保存于恢复

    数据保存于恢复 用户操作(输入数据)之后,应用程序退出并且终止之后,当用户再次打开应用的时候还是保持原来的状态 一:在storyBoard中设置恢复标志符 二:在AppDalegate中代理方法 -( ...

  4. cocos2dx实例开发之flappybird(入门版)

    cocos2dx社区里有个系列博客完整地复制原版flappybird的全部特性.只是那个代码写得比較复杂,新手学习起来有点捉摸不透,这里我写了个简单的版本号.演演示样例如以下: watermark/2 ...

  5. javascript代码解释执行过程

    javascript是由浏览器解释执行的脚本语言,不同于java c,需要先编译后运行,javascript 由浏览器js解释器进行解释执行,总的过程分为两大块,预编译期和执行期 下面的几个demo解 ...

  6. Linux内存管理学习笔记 转

    https://yq.aliyun.com/articles/11192?spm=0.0.0.0.hq1MsD 随着要维护的服务器增多,遇到的各种稀奇古怪的问题也会增多,要想彻底解决这些“小”问题往往 ...

  7. C#实现ByteBuffer类 .

    在写网络程序的时候,经常需要往一个数组里面压数据或者取数据,而Java中再Java.nio中有个ByteBuffer能很方便的实现,Delphi中也有个Stream类有着同样的功能,这里我就模仿JAV ...

  8. 配置apache、php、mysql之间的关系

    1.index.php文件放入/usr/local/apache2/htdocs 目录下 其中index.php里面内容为: <?php phpinfo(); $dbc= mysql_conne ...

  9. C++实现日期转换类DateTime

    概述 工作中我们在网络传输时使用time_t来传输时间,在显示时使用字符串来显示,下面是一个日期转换类的实现,方便以后使用: // DateTime.hpp #ifndef _DATETIME_H # ...

  10. jquery . fancybox()

    1.父页面 function chooseTopic(btn) {//选择议题 $.fancybox({ type : 'iframe', href : '', fitToView : false, ...