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

    }

  • 相关阅读:
    jmeter上做分布压测
    jpg,jpeg,bmp,png,gif图片格式区别
    jmeter的命令行进行压力测试
    Java8新特性
    02-Git
    01-Maven
    Java-集合
    Java-I/O框架
    mongodb安装配置
    Nginx常见错误及处理方法
  • 原文地址:https://www.cnblogs.com/qiangzheVSruozhe/p/9366675.html
Copyright © 2011-2022 走看看