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

九宫格的实现

时间:2016-05-17 00:44:52      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

//
//  ViewController.m
//  九宫格的实现
//
//  Created by Hunter_Wang on 15/11/27.
//  Copyright © 2015年 HaiTeng. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    ///////////////////////////////////////
    // 搭建界面,九宫格
#define kAppViewW 70
#define kAppViewH 30
#define kColCount 4
#define kStartY   20
    
    // 320 - 3 * 80 = 80 / 4 = 20
    CGFloat marginX = (self.view.bounds.size.width - kColCount * kAppViewW) / (kColCount + 1);
    CGFloat marginY = 10;
    
    for (int i = 0; i < 7; i++) {
        //// 0, 1, 2 => 0
        // 3, 4, 5 => 1
        int row = i / kColCount;
        
        //// 0, 3, 6 => 0
        // 1, 4, 7 => 1
        // 2, 5, 8 => 2
        int col = i % kColCount;
        
        CGFloat x = marginX + col * (marginX + kAppViewW);
        CGFloat y = kStartY + marginY + row * (marginY + kAppViewH);
        
        UIView *appView = [[UIView alloc] initWithFrame:CGRectMake(x, y, kAppViewW, kAppViewH)];
                appView.backgroundColor = [UIColor redColor];
        appView.layer.masksToBounds = YES;
        appView.layer.cornerRadius = 15;
        appView.layer.borderWidth = 1;
        appView.layer.borderColor = [UIColor grayColor].CGColor;
        [self.view addSubview:appView];
        
    }
    ///////////////////////////////////////
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

 

九宫格的实现

标签:

原文地址:http://www.cnblogs.com/HaiTeng/p/5500076.html

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