zoukankan      html  css  js  c++  java
  • 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];
    }
    
  • 相关阅读:
    linux du命令
    Linux vmstat命令实战详解
    linux sar命令详解
    xargs 命令教程
    Linux中find命令用法大全
    python suprocess
    Python的f-strings格式化
    python glob的使用
    python getopt()的使用
    Java测试的题目感想
  • 原文地址:https://www.cnblogs.com/0515offer/p/4638417.html
Copyright © 2011-2022 走看看