一、Masonry简介

Masonry是一个轻量级的布局框架,它拥有自己的描述语法(采用更优雅的链式语法封装)来自动布局,具有很好可读性且同时支持iOS和Max OS X等。

二、Masonry的基本使用方法

    [控件 mas_makeConstraints:^(MASConstraintMaker *make) {
//这个方法只会添加新的约束
}]; [控件 mas_remakeConstraints:^(MASConstraintMaker *make) {
//这个方法会将以前的约束全部删除,添加新的约束
}]; [控件 mas_updateConstraints:^(MASConstraintMaker *make) {
//这个方法将会覆盖以前的某些特定的约束
}];

三、约束的基本属性

@property (nonatomic, strong, readonly) MASConstraint *left;

@property (nonatomic, strong, readonly) MASConstraint *top;

@property (nonatomic, strong, readonly) MASConstraint *right;

@property (nonatomic, strong, readonly) MASConstraint *bottom;

//首部

@property (nonatomic, strong, readonly) MASConstraint *leading;

//尾部

@property (nonatomic, strong, readonly) MASConstraint *trailing;

@property (nonatomic, strong, readonly) MASConstraint *width;

@property (nonatomic, strong, readonly) MASConstraint *height;

@property (nonatomic, strong, readonly) MASConstraint *centerX;

@property (nonatomic, strong, readonly) MASConstraint *centerY;

//文本基线

@property (nonatomic, strong, readonly) MASConstraint *baseline;


四、约束的特殊属性

//(top, left, bottom, right)

@property (nonatomic, strong, readonly) MASConstraint *edges;

//(width, height)

@property (nonatomic, strong, readonly) MASConstraint *size;

//(centerX, centerY)

@property (nonatomic, strong, readonly) MASConstraint *center;

五、基本使用

//加入这个宏,可以省略所有 mas_ (除了mas_equalTo)

#define MAS_SHORTHAND

//加入这个宏,那么mas_equalTo就和equalTo一样的了

#define MAS_SHORTHAND_GLOBALS

//上面的两个宏一定要在这句之前

#import <Masonry/Masonry.h>

//创建发起会话弹框

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

tipView.backgroundColor=[UIColor greenColor];

//self.tipView.frame=CGRectMake(0, 0, K_CC_SCREEN_WIDTH, 35);

//先添加,再设置约束,否则报错

[self.view addSubview:tipView];

[tipView mas_makeConstraints:^(MASConstraintMaker *make) {

//1、设置tipView的中心点x等于self.view的中心点的x

//make.centerX.equalTo(self.view);

//设置tipView等顶部等于self.view的顶部,同时偏移30

//make.top.equalTo(self.view).offset(30);

//设置宽和高

//make.size.mas_equalTo(CGSizeMake(300, 200));

//2、设置tipView的中心点等于self.view的中心点

//make.center.equalTo(self.view);

//等同于下面

//make.centerX.mas_equalTo(self.view.mas_centerX);

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

//设置宽和高

//make.size.mas_equalTo(CGSizeMake(300, 200));

//3、注意mas_equalTo后面对应的是数值,equalTo后面跟的是一个对象

//4、设置tipView的宽和高

//make.size.mas_equalTo(CGSizeMake(300, 200));

//make.width.mas_equalTo(300);

//make.height.mas_equalTo(200);

//右边距20,x轴向左是正数,向右是负数

//make.right.equalTo(self.view).offset(-20);

//底部边距20

//make.bottom.equalTo(self.view).offset(-20);

//5、tipView的宽和高等于父控件的一半

/*make.size.equalTo(self.view).multipliedBy(0.5);

make.right.mas_equalTo(self.view.mas_right).offset(-20);

make.bottom.mas_equalTo(self.view.mas_bottom).offset(-20);*/

//6、距离各个边距50

/*make.left.mas_equalTo(self.view.mas_left).offset(50);

make.top.mas_equalTo(self.view.mas_top).offset(50);

make.bottom.mas_equalTo(self.view.mas_bottom).offset(-50);

make.right.mas_equalTo(self.view.mas_right).offset(-50);*/

/*make.left.mas_equalTo(50);

make.top.mas_equalTo(50);

make.bottom.mas_equalTo(-50);

make.right.mas_equalTo(-50);*/

//此时设置的是数值,不用算正负

make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(50, 50, 50, 50));

}];

//警告内容

UILabel *lblTip = [[UILabel alloc]init];

lblTip.backgroundColor = [UIColor clearColor];

lblTip.textColor=[UIColor blackColor];

lblTip.textAlignment = NSTextAlignmentCenter;

lblTip.font = [UIFont systemFontOfSize:15];

lblTip.adjustsFontSizeToFitWidth = YES;

//lblTip.frame = CGRectMake(0, 0, K_CC_SCREEN_WIDTH, 35);

lblTip.text = @"只能选择使用群策的用户进行聊天";

[tipView addSubview:lblTip];

//    [lblTip mas_makeConstraints:^(MASConstraintMaker *make) {

////        make.width.mas_equalTo(390);

//        make.height.mas_equalTo(18);

//        make.centerX.mas_equalTo(self.tipView.mas_centerX);

//        make.centerY.mas_equalTo(self.tipView.mas_centerY);

//    }];

[lblTip mas_makeConstraints:^(MASConstraintMaker *make) {

make.center.equalTo(tipView);

make.width.mas_equalTo(200);

make.height.mas_equalTo(18);

}];

//警告图标

UIImageView *imageTip = [[UIImageView alloc]init];

[imageTip setImage:[UIImage imageNamed:@"群策警告"]];

[tipView addSubview:imageTip];

//    [imageTip mas_makeConstraints:^(MASConstraintMaker *make) {

//        make.width.mas_equalTo(15);

//        make.height.mas_equalTo(15);

//        make.right.mas_equalTo(lblTip.mas_left).offset(-5);

//        make.top.mas_equalTo(10);

//    }];

[imageTip mas_makeConstraints:^(MASConstraintMaker *make) {

make.width.mas_equalTo(15);

make.height.mas_equalTo(15);

make.right.mas_equalTo(lblTip.mas_left).offset(-5);

make.centerY.equalTo(tipView.mas_centerY);

}];

 

iOS Masonry使用小结的更多相关文章

  1. iOS:Masonry介绍与使用

    Masonry介绍与使用实践:快速上手Autolayout   frame----->autoresing------->autoLayout-------->sizeClasses ...

  2. iOS GCD 编程小结

    一.简单介绍 1.GCD简介? 全称是Grand Central Dispatch,可译为“牛逼的中枢调度器” 纯C语言,提供了非常多强大的函数 2.GCD优势 GCD是苹果公司为多核的并行运算提出的 ...

  3. iOS静态库小结--(yoowei)

    准备知识: 1.什么是库? 库是程序代码的集合,是共享程序代码的一种方式 2.根据源代码的公开情况,库可以分为2种类型 a.开源库 公开源代码,能看到具体实现 ,比如SDWebImage.AFNetw ...

  4. iOS masonry九宫格 单行 多行布局

    Masonry是个好东西,在当前尺寸各异的iOS开发适配中发挥着至关重要的作用,由于项目中Masonry布局用的比较多,对于UI布局也有了一些自己的理解,经常会有人问道Masonry布局九宫格要怎么布 ...

  5. iOS Masonry的使用需要注意的地方

    自动布局最重要的是约束:UI元素间关系的数学表达式.约束包括尺寸.由优先级和阈值管理的相对位置.它们是添加剂,可能导致约束冲突 .约束不足造成布局无法确定 .这两种情况都会产生异常. 使用前:Auto ...

  6. iOS masonry布局在iOS11/12上正常 iOS9/10却异常

    使用masonry布局,可以布局一套,适配所有机型,但是有时候会出现一些比较特殊的情况,每次iOS11上面开发,开发完成之后,在iOS9,iOS10上查看的时候发现布局与iOS11不完全一致,有的高度 ...

  7. iOS推送小结(证书的生成、客户端的开发、服务端的开发)

    1.推送过程简介 1.1.App启动过程中,使用UIApplication::registerForRemoteNotificationTypes函数与苹果的APNS服务器通信,发出注册远程推送的申请 ...

  8. ios - GCD简单小结

    首先GCD两个名词: 队列 同步异步. 队列: 任务放到队列,队列中的任务执行方式取决于执行队列中任务的方式---同步异步. 串行队列: 任务顺序执行,可以叫阻塞队列.只有前面任务完成才执行后面的. ...

  9. IOS文件存储小结

    转自:http://tyragain.lofter.com/post/84706_c1503 首选项设置存储 NSUserDefaults 以及通过它控制的SettingBundle  NSUserD ...

  10. AIR for IOS开发问题小结

    昨天终于成功地向APP STORE提交了应用,个人感觉用AIR做IOS开发就是个坑啊.出了问题之后,问苹果的技术支持,人家说“对于非XCODE环境下开发及发布所造成的问题我们在资料库中无法找到相应的解 ...

随机推荐

  1. 【MySQL】Windows-5.7.30 解压版 下载安装

    1.Download 下载 mysql官网: https://dev.mysql.com/ 找到download点击进入下载页面: https://dev.mysql.com/downloads/ 找 ...

  2. 国产AI训练卡,对标美国NVIDIA公司的A100,华为昇腾Atlas 300T A2(Ascend 910B4)高性能GPU/NPU/AI推理/国产计算/信创训练卡 —— 电商平台已开售

    China has successfully achieved the localization of AI chips, breaking through the technological res ...

  3. 安装wsl的必备操作——开启CPU虚拟化——WslRegisterDistribution failed with error_ 0x8007019e 0x800701b 0x80370102 请启用虚拟机平台

    参考: https://www.cnblogs.com/smdtxz/p/16837946.html https://www.cnblogs.com/wenonly/p/17206040.html h ...

  4. 使用TensorFlow、Pytorch等深度学习框架时如何设置对OpenCV的使用

    如题: 在使用深度学习框架时如果同时也在使用opencv那么有一些设置是需要设定的,第一个就是在python代码中设定禁止使用opencl: cv2.ocl.setUseOpenCL(False) o ...

  5. 在python中numpy.sum的性能真的好吗

    首先我们应该知道np.sum是用C语言写的矢量计算,应用场景为规模较大的numpy数组求和.本文要说的就是numpy.sum是不是对规模较小的numpy数组求和也同样会有不错的性能? 代码: impo ...

  6. 解决CGLib动态代理测试不通过-Unable to load cache item

    1.背景 在学习aop底层时遇到的问题,做个小结 2.现象 动态代理代码如下: package com.ldp.proxy; import net.sf.cglib.proxy.Enhancer; i ...

  7. Apache SeaTunnel社区首位学生Committer诞生!

    采访对象 | 陈炳烨 采访人&编辑 | Debra Chen Apache SeaTunnel社区第一位学生Committer就此诞生!这位来自西安交通大学软件工程专业的同学从较为简单的文档修 ...

  8. 通过内存映射的方式向lcd屏幕输出几个圆

    /************************************************* * * file name:color.c * author :momolyl@126.com * ...

  9. python增删查改实例

    本文介绍一个实例,即删除数据库中原有的表格TEST1,新建一个表格TEST2,并在TEST2中插入3行数据.插入数据以后,查询出ID=3的数据,读出,最后将其删除. 结果: 代码: ''' impor ...

  10. inline,static inline

    https://blog.csdn.net/A_BCDEF_/article/details/89485894 inline 函数被调用时,需要出栈入栈.当函数频繁被调用时,则不断地有函数出栈入栈,会 ...