zoukankan      html  css  js  c++  java
  • Masonry的使用

    Masonry是一个轻量级的布局框架 拥有自己的描述语法 采用更优雅的链式语法封装自动布局,简洁明了,并具有高可读性,而且同时支持 iOS 和 Max OS X。

    如果使用系统带的NSLayoutConstraint代码量将非常大,同时还不好使用。

    下面是使用源码链接 <a href="https://github.com/SnapKit/Masonry">Masonry源码</a>

    1.居中显示

       UIView *sv = [UIView new];

        sv.backgroundColor = [UIColor greenColor];

        [self.view addSubview:sv];

        [sv mas_makeConstraints:^(MASConstraintMaker *make) {

            make.top.equalTo(@20);

            make.left.equalTo(@20);

            make.bottom.equalTo(@-20);

            make.right.equalTo(@-20);

        }];

     

    2.设置视图并排

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

        view1.backgroundColor = [UIColor redColor];

        [self.view addSubview:view1];

        

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

        view2.backgroundColor = [UIColor yellowColor];

        [self.view addSubview:view2];

        

        

        int padding = 10;

        

        [view1 mas_makeConstraints:^(MASConstraintMaker *make) {

            

            // 设置其位于父视图的Y的中心位置

            make.centerY.mas_equalTo(self.view.mas_centerY);

            // 设置其左侧和父视图偏移10个像素

            make.left.equalTo(self.view).with.offset(padding);

            // 设置其右侧和view2偏移10个像素

            make.right.equalTo(view2.mas_left).with.offset(-padding);

            // 设置高度

            make.height.mas_equalTo(@120);

            // 设置其宽度

            make.width.equalTo(view2);

        }];

        

        [view2 mas_makeConstraints:^(MASConstraintMaker *make) {

            make.centerY.mas_equalTo(self.view.mas_centerY);

            make.left.equalTo(view1.mas_right).with.offset(padding);

            make.right.equalTo(self.view).with.offset(-padding);

            make.height.mas_equalTo(view1);

            make.width.equalTo(view1);

        }];

     

  • 相关阅读:
    Windows Python+Eclipse环境配置
    infobright系列二:数据迁移
    infobright系列一:源码安装infobright
    autotools归纳
    Atlas系列一:Atlas功能特点FAQ
    C#反射技术概念作用和要点
    .net获取本机公网IP代码
    Java泛型-类型擦除
    现在就使用HTML5的十大原因
    让网页图片变灰色的三种方法
  • 原文地址:https://www.cnblogs.com/menchao/p/4844632.html
Copyright © 2011-2022 走看看