//
// 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. javascript之处理Ajax错误

    使用Ajax须留心两类错误.它们的差别源于视角的不同. 第一类错误是从XMLHttpRequest对象的角度看到的问题:某些因素阻止了请求发送到server,比如DNS无法解析主机名,连接请求被拒绝. ...

  2. Mac OS系统

    Mac OS系统 目录 概述 Mac OS系统常用操作 概述 Mac OS系统常用操作 显示或隐藏文件 在终端输入:defaults write com.apple.finder AppleShowA ...

  3. JavaScript目录

    1. 如何快速检查js语法学习Javascript 2. 如何快速掌握CSS(各种CSS工具)

  4. c基础补充

    一:字符串在C语言中 字符串一般是动态分配和字符数组两种形式 动态分配的时候字符串字符串指针是4个字节 字符串的大小根据自己的需要来申请 比如: char * c://C为字符串指针 占用四个字节 c ...

  5. Use Spring Insight Developer to Analyze Code, Install it with Tomcat, and Extend it with Plugins--转载

    原文地址:http://www.tomcatexpert.com/blog/2012/12/05/use-spring-insight-developer-analyze-code-install-i ...

  6. LeetCode28 Implement strStr()

    题目: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if ne ...

  7. IOS UITableView Group&Section

    UItableView 根据数据结构不同 会有不同样式 关键在两个代理 tableviewdelegate&tabledatasourse 下面代码是我实施的Group 在模拟器中 ios6. ...

  8. 【Android 界面效果38】android:inputType常用取值

    <EditText android:layout_width="fill_parent" android:layout_height="wrap_content&q ...

  9. 【谷歌市场安装】Google Play 闪退问题解决

    Google Play 安装后闪退,是因为手机没有内置GMS(Google Mobile Service) 框架. 由于谷歌退出了中国市场,国产手机很多都没有内置GMS, 导致Google Play ...

  10. MyEclipse设置编码方式 转载【http://www.cnblogs.com/susuyu/archive/2012/06/27/2566062.html】

    1.windows->Preferences……打开"首选项"对话框,左侧导航树,导航到general->Workspace, 右侧Text file encoding ...