• 代码:Masonry 第三方框架


    必备宏使用前提:
    //define this constant if you want to use Masonry without the 'mas_' prefix
    #define MAS_SHORTHAND
    //define this constant if you want to enable auto-boxing for default syntax
    #define MAS_SHORTHAND_GLOBALS
    #import "Masonry.h"
     
     
    代码实现 :
    // 蓝色控件
        UIView *blueView = [[UIView alloc] init];
        blueView.backgroundColor = [UIColor blueColor];
        [self.view addSubview:blueView];
       
        // 红色控件
        UIView *redView = [[UIView alloc] init];
        redView.backgroundColor = [UIColor redColor];
        [self.view addSubview:redView];
       
        // 添加约束
        CGFloat margin = 20;//这是抽取的值,下面我用实例说明:可以直接使用数字
        CGFloat height = 50;
        //添加蓝色的约束:只要用蓝色视图调用这个方法,下面就不需要写blueView
        [blueView makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view.left).offset(20);//视图的左边等于父视图的左边并修正多少
            make.right.equalTo(redView.left).offset(-20);//视图的右边边等于红色视图的右边并修正多少
            make.bottom.equalTo(self.view.bottom).offset(-margin);
            make.height.equalTo(height);//视图高度等于一个固定高度
            make.top.equalTo(redView.top);// 视图的上面和红色视图的上面相等
            make.bottom.equalTo(redView.bottom);// 视图的下面和红色视图的下面相等
            make.width.equalTo(redView.width);// 视图的宽度和红色视图的宽度相等
        }];
        //添加红色视图的约束
        [redView makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.view.right).offset(-margin);
        }];
     
     
  • 相关阅读:
    理解HashSet及使用
    Java 集合类详解
    Java-泛型编程-使用通配符? extends 和 ? super
    回调函数及其用法
    log4j.properties 详解与配置步骤
    约瑟夫环
    泛型的约束与局限性
    把代码字体加大的办法
    System.arraycopy方法
    泛型数组列表与反射
  • 原文地址:https://www.cnblogs.com/wahy/p/5014996.html
Copyright © 2020-2023  润新知