标签:
// // 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