首页 > 其他 > 详细

九宫格的实现

时间:2016-05-17 00:41:56      阅读:183      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!