zoukankan      html  css  js  c++  java
  • masonry框架的使用之-多个视图的均匀等间距分布

    __weak typeof(self) weakSelf = self; //对self进行weak化,否则造成循环引用无法释放controller

    UIView * tempView = [[UIView alloc]init];
    NSInteger count = 10;//设置一排view的个数
    NSInteger margin = 10;//设置相隔距离
    NSInteger height = 50;//设置view的高度
    for (int i = 0; i < count; i ++) {
    UIView * view = [[UIView alloc]init];
    view.backgroundColor = [UIColor brownColor];
    [self.view addSubview:view];
    if (i == 0) {
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.equalTo(weakSelf.view).offset(margin);
    make.centerY.equalTo(weakSelf.view);
    make.height.mas_equalTo(height);
    }];
    }
    else if (i == count – 1){
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
    make.right.equalTo(weakSelf.view).offset(-margin);
    make.left.equalTo(tempView.mas_right).offset(margin);
    make.centerY.equalTo(tempView);
    make.height.equalTo(tempView);
    make.width.equalTo(tempView);
    }];
    }
    else{
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.equalTo(tempView.mas_right).offset(margin);
    make.centerY.equalTo(tempView);
    make.height.equalTo(tempView);
    make.width.equalTo(tempView);
    }];
    }
    tempView = view;
    [view layoutIfNeeded];
    }

  • 相关阅读:
    伯努利数学习笔记
    贝尔数学习笔记
    LuoguP5075 [JSOI2012]分零食
    LuoguP5748 集合划分计数
    LuoguP3338 [ZJOI2014]力
    LuoguP5488 差分与前缀和
    BZOJ4833 [Lydsy1704月赛]最小公倍佩尔数
    FFT&NTT学习笔记
    csp2019游记
    与图论的邂逅09:树上启发式合并
  • 原文地址:https://www.cnblogs.com/Jordandan/p/4929611.html
Copyright © 2011-2022 走看看