行列

/

// ViewController.m

// 九宫格

//

// Created by hlz on 16/2/29.

// Copyright © 2016年 hlz. All rights reserved.

//

import "ViewController.h"

CGFloat viewW;//小视图的宽

CGFloat viewH;//小的VIEW的高

int count=20;//放的图标的个数

int columns=3;//列数

CGFloat margin=20;//边距

@interfaceViewController()

@end

@implementation ViewController

  • (void)viewDidLoad

{

  [superviewDidLoad];

  viewW=(CGRectGetWidth(self.view.frame)-(columns+1)*margin)/columns;//求 出小视图的宽度

   viewH=viewW;//设置高度等于宽度

  for (int i=0; i

     {

    UIView *view=[[UIView alloc]init];//创建视图

    [self.view addSubview:view];

    int row=i/columns;//获取图标的行下标

    int col=i%columns;//获取当前图标的列下标

    CGFloat viewX=margin+col*(viewW+margin);

    CGFloat viewY=margin+row*(viewH+margin);

    view.frame=CGRectMake(viewX, viewY, viewW, viewH);

    view.backgroundColor=[UIColorgreenColor];

           }



// Do any additional setup after loading the

}

  • (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

@end

作者:yindusu
来源:CSDN
原文:https://blog.csdn.net/yindusu/article/details/81205910
版权声明:本文为博主原创文章,转载请附上博文链接!

你可能感兴趣的:(行列)