zoukankan      html  css  js  c++  java
  • 56.九宫格布局

    - (void)viewDidLoad {

        [super viewDidLoad];

        //每个Item宽高

        CGFloat W = 80;

        CGFloat H = 100;

        //每行列数

        NSInteger rank = 3;

        //每列间距

        CGFloat rankMargin = (self.view.frame.size.width - rank*W)/(rank+1);

      

        //每行间距

        CGFloat rowMargin = 20;

        //Item索引 -->根据需求改变索引

        NSUInteger index = 9;

        

        for (int i = 0; i<index ; i++) {

            //Item  X 轴

            CGFloat X = (i%rank)*(W+rankMargin)+rankMargin;

            //Item Y轴

            NSUInteger Y = (i/rank)*(H+rowMargin);

            //Item top

            CGFloat top = 50;

            UIView *speedView = [[UIView alloc]init];

            speedView.tag = i;

            speedView.frame = CGRectMake(X, Y+top, W, H);

            UIImage *image = [UIImage imageNamed:@"IMG_0449"];

            speedView.layer.contents = (id)image.CGImage;

            

            [self.view addSubview:speedView];

            

            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];

            tap.view.tag = speedView.tag;

            [speedView addGestureRecognizer:tap];

            

        }

    }

    -(void)tap:(UITapGestureRecognizer*)GestureRecognizer{

        NSLog(@"======%ld",GestureRecognizer.view.tag);//lable的tag

    }

  • 相关阅读:
    Gin框架系列02:路由与参数
    Gin框架系列01:极速上手
    Go语言库系列之email
    Go语言库系列之aurora
    Go语言库系列之dotsql
    Go语言库系列之flag
    Go解算法07整数反转
    Go语言micro之快速搭建微服务
    理解Golang组件protobuf
    理解Go语言组件flag
  • 原文地址:https://www.cnblogs.com/qiangzheVSruozhe/p/9366675.html
Copyright © 2011-2022 走看看