码迷,mamicode.com
首页 > 其他好文 > 详细

UIView实现红黑棋盘

时间:2015-08-15 21:38:29      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:

//  Created by 妖精的尾巴 on 15-8-15.

//  Copyright (c) 2015 妖精的尾巴. All rights reserved.

//


#import "ViewController.h"

#define kHeight 20

@interface ViewController ()

@end


@implementation ViewController


- (void)viewDidLoad

{

    [super viewDidLoad];

    UIView* view=[[UIView alloc]initWithFrame:CGRectMake(0, kHeight, 320, 320)];

    view.backgroundColor=[UIColor redColor];

    [self.view addSubview:view];

    for (int col=0; col<320; col+=40) {

        for (int row=0; row<320; row+=40)

        {

            UIView* redView=[[UIView alloc]initWithFrame:CGRectMake(row, col, kHeight, kHeight)];

            redView.backgroundColor=[UIColor blackColor];

            [view addSubview:redView];

        }

        for (int row=20; row<320; row+=40)

        {

            UIView* redView=[[UIView alloc]initWithFrame:CGRectMake(row, col+kHeight, kHeight, kHeight)];

            redView.backgroundColor=[UIColor blackColor];

            [view addSubview:redView];

        }

    }

}

技术分享

UIView实现红黑棋盘

标签:

原文地址:http://my.oschina.net/iOSliuhui/blog/492993

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!