zoukankan      html  css  js  c++  java
  • Masonry的一些等间距布局

    • 控件之间的间距相等,但是控件的宽度是不定的。

      下列的代码:定义间距为10,yellowview的宽度是由redView的宽度计算出来的。

        UIView *redView = [[UIView alloc]init];
        redView.backgroundColor = [UIColor redColor];
        [self.view addSubview:redView];
        [redView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(ws.view);
            make.top.mas_equalTo(ws.view);
            make.right.mas_equalTo(ws.view);
        }];
        
        NSInteger padding = 10;
        UIView *yellowView1 = [[UIView alloc] init];
        yellowView1.backgroundColor = [UIColor yellowColor];
        [redView addSubview:yellowView1];
        
        UIView *yellowView2 = [[UIView alloc] init];
        yellowView2.backgroundColor = [UIColor yellowColor];
        [redView addSubview:yellowView2];
        
        UIView *yellowView3 = [[UIView alloc] init];
        yellowView3.backgroundColor = [UIColor yellowColor];
        [redView addSubview:yellowView3];
        
        [@[yellowView1,yellowView2,yellowView3] mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:padding leadSpacing:padding tailSpacing:padding];
        
        [@[yellowView1,yellowView2,yellowView3] mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(redView).offset(padding);
            make.height.mas_equalTo(yellowView1.mas_width);
            make.bottom.mas_equalTo(redView).offset(-padding);
        }];
    • 控件的宽度是一定的,但是控件之间的间距是不定的。

      下列的代码:定义控件的宽度为22,控件之间的间距是由redView的宽度计算出来的。

        UIView *redView = [[UIView alloc]init];
        redView.backgroundColor = [UIColor redColor];
        [self.view addSubview:redView];
        [redView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(ws.view);
            make.top.mas_equalTo(ws.view);
            make.right.mas_equalTo(ws.view);
        }];
        
        UIView *yellowView1 = [[UIView alloc] init];
        yellowView1.backgroundColor = [UIColor yellowColor];
        [redView addSubview:yellowView1];
        
        UIView *yellowView2 = [[UIView alloc] init];
        yellowView2.backgroundColor = [UIColor yellowColor];
        [redView addSubview:yellowView2];
        
        UIView *yellowView3 = [[UIView alloc] init];
        yellowView3.backgroundColor = [UIColor yellowColor];
        [redView addSubview:yellowView3];
        
        //控件的宽度
        CGFloat viewW = 22;
        CGFloat padding = (SCREENWIDTH - 3*viewW) * 1.0 / 4;
        
        [@[yellowView1,yellowView2,yellowView3] mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedItemLength:viewW leadSpacing:padding tailSpacing:padding];
        
        [@[yellowView1,yellowView2,yellowView3] mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(redView).offset(padding);
            make.size.mas_equalTo(viewW);
            make.bottom.mas_equalTo(redView).offset(-padding);
        }];
  • 相关阅读:
    刷新dbgrid 而不失去当前行位置
    Delphi Code Editor 之 快捷菜单
    Delphi Code Editor 之 几个特性(转)
    Delphi DBGrid双击事件、单元格操作
    在DBGrid中可选中行而又可进入编辑状态
    如何在DBGrid中能支持多项记录的选择
    在Delphi中如何获得SQL中存储过程的返回值?
    Delphi:ADOConnection连接SQLServer自动断网问题解决
    ADO.NET基础必备之SqlCommand.Execute三方法
    Delphi中exit、break、continue等跳出操作的区别
  • 原文地址:https://www.cnblogs.com/iOSDeng/p/6121380.html
Copyright © 2011-2022 走看看