//
// 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. 跟大家分享下今天所学到的PHP,虽然很基础,但是感觉也很重要

    PHP:Hypertext PreProcessor(超文本预处理语言) PHP是一种服务器端语言(server-side language),服务器只发送脚本的输出,通常是HTML,PHP也可以用于 ...

  2. data URI scheme

    优化网页效能,首要的任务是尽量减少HTTP请求(http request)的次数,例如把多个JavaScript文档合并,多个CSS文件合并等等.此外,还有有一种 data URL 的方法,可以直接把 ...

  3. 用iDSDT制作声显卡DSDT

    已有 2299 次阅读2011-10-24 21:00 |个人分类:Mac| DSDT 快速增加积分秘笈! windows下!--------------------------------第一步.下 ...

  4. WIN7 下 Qt Creator 安装 QWT

    WIN7 下 Qt Creator 安装 QWT 环境:WIN7 +QT Creator2.6.2 1.下载QWT源代码 qwt-6.1-rc3.zip 2 编译QWT  open projects- ...

  5. VC6.0常见编译错误提示

    原文:http://c.biancheng.net/cpp/html/746.html 1) error C2001: newline in constant 编号:C2001 直译:在常量中出现了换 ...

  6. U_boot 的 bootcmd 和bootargs参数详解

    转自 :http://linux.chinaunix.net/bbs/archiver/tid-1111568.html U-boot的环境变量值得注意的有两个: bootcmd 和bootargs. ...

  7. kafka java客户端编程

    kafka_2.10-0.8.1.1 maven <dependencies> <dependency> <groupId>org.apache.kafka< ...

  8. java发送邮件 实现编辑html代码

    这个例子相当的简单,一看就懂(  此例仅支持163发送163及qq邮箱) 首先要导入两个必须jar包:mail-1.4.4.jar 和 commons-email-1.2.jar这两个jar包是我用的 ...

  9. JS实现滚动条滚到页面距离底部300px时执行事件的方法

    scrollTop为滚动条在Y轴上的滚动距离. clientHeight为内容可视区域的高度. scrollHeight为内容可视区域的高度加上溢出(滚动)的距离 $(window).scroll(f ...

  10. 【开源项目6】介绍MenuDrawer这个牛x的控件,实现左右出菜单,上下出菜单

    现在很多应用都很潇洒的从左边屏幕手势一划出个左边的隐藏菜单,右边一划出个隐藏菜单,上边一划出个隐藏菜单,下边一划出个隐藏菜单.或者像android的API16左右的激活列表项的功能.很多人肯定都很着迷 ...