iOS Masonry使用小结
一、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使用小结的更多相关文章
- iOS:Masonry介绍与使用
Masonry介绍与使用实践:快速上手Autolayout frame----->autoresing------->autoLayout-------->sizeClasses ...
- iOS GCD 编程小结
一.简单介绍 1.GCD简介? 全称是Grand Central Dispatch,可译为“牛逼的中枢调度器” 纯C语言,提供了非常多强大的函数 2.GCD优势 GCD是苹果公司为多核的并行运算提出的 ...
- iOS静态库小结--(yoowei)
准备知识: 1.什么是库? 库是程序代码的集合,是共享程序代码的一种方式 2.根据源代码的公开情况,库可以分为2种类型 a.开源库 公开源代码,能看到具体实现 ,比如SDWebImage.AFNetw ...
- iOS masonry九宫格 单行 多行布局
Masonry是个好东西,在当前尺寸各异的iOS开发适配中发挥着至关重要的作用,由于项目中Masonry布局用的比较多,对于UI布局也有了一些自己的理解,经常会有人问道Masonry布局九宫格要怎么布 ...
- iOS Masonry的使用需要注意的地方
自动布局最重要的是约束:UI元素间关系的数学表达式.约束包括尺寸.由优先级和阈值管理的相对位置.它们是添加剂,可能导致约束冲突 .约束不足造成布局无法确定 .这两种情况都会产生异常. 使用前:Auto ...
- iOS masonry布局在iOS11/12上正常 iOS9/10却异常
使用masonry布局,可以布局一套,适配所有机型,但是有时候会出现一些比较特殊的情况,每次iOS11上面开发,开发完成之后,在iOS9,iOS10上查看的时候发现布局与iOS11不完全一致,有的高度 ...
- iOS推送小结(证书的生成、客户端的开发、服务端的开发)
1.推送过程简介 1.1.App启动过程中,使用UIApplication::registerForRemoteNotificationTypes函数与苹果的APNS服务器通信,发出注册远程推送的申请 ...
- ios - GCD简单小结
首先GCD两个名词: 队列 同步异步. 队列: 任务放到队列,队列中的任务执行方式取决于执行队列中任务的方式---同步异步. 串行队列: 任务顺序执行,可以叫阻塞队列.只有前面任务完成才执行后面的. ...
- IOS文件存储小结
转自:http://tyragain.lofter.com/post/84706_c1503 首选项设置存储 NSUserDefaults 以及通过它控制的SettingBundle NSUserD ...
- AIR for IOS开发问题小结
昨天终于成功地向APP STORE提交了应用,个人感觉用AIR做IOS开发就是个坑啊.出了问题之后,问苹果的技术支持,人家说“对于非XCODE环境下开发及发布所造成的问题我们在资料库中无法找到相应的解 ...
随机推荐
- windows环境xampp搭建php电商项目/搭建禅道
windows环境xampp搭建php论坛/电商项目 一,首先下载xampp https://www.apachefriends.org/zh_cn/index.html 下载之后解压到E盘或者F盘的 ...
- 【Vue】接口模块化处理
在前端Vue项目中,接口会被统一放在一个目录中管理: 一个模块的所有接口放在一个JS文件中: 文件会导入封装好的请求方法,和动态绑定的接口地址 import request from '@/utils ...
- plsql中的常用功能整理
1.关键字查找 2.保存登录密码 完美!
- http与https通俗易懂的原理解析
1.背景 经常都在说http.https,都知道https是安全的, 但是, 为什么说http不安全呢? 为什么又说https是安全的呢? 接下来我将使用通俗易懂的方式给大家分析一下....... 2 ...
- Java数组小白版
一.数组概念 一.数组定义 数组就是指在计算机内存中开辟的连续存储空间,用于存放程序运行中需要用到的一组相同类型数据的容器. 二.数组的声明 +数组的长度 定义数组时需要确定数组的长度(元素的个数), ...
- jxls导入excel
我们在开发中经常用jxls实现导出功能,殊不知jxls也有导入功能,下面来介绍下如何使用jxls导入excel. 首先在maven的pom中添加相关依赖,如下: <dependency> ...
- 【A GUIDE TO CRC ERROR DETECTION ALGORITHM】 (译文1)
A GUIDE TO CRC ERROR DETECTION ALGORITHM (译文) <A PAINLESS GUIDE TO CRC ERROR DETECTION ALGORITHM& ...
- 【YashanDB知识库】stmt未close,导致YAS-00103 no free block in sql main pool part 0报错分析
问题现象 问题单:YAS-00103 no free block in sql main pool part 0,YAS-00105 out of memory to allocate hash ta ...
- 分布式缓存应用场景与redis持久化机制
redis 参考目录: 生产级Redis 高并发分布式锁实战1:高并发分布式锁如何实现 https://www.cnblogs.com/yizhiamumu/p/16556153.html 生产级Re ...
- C语言linux系统fork函数
References: c语言fork函数 linux中fork()函数详解 一.fork函数简介 作用 在linux下,C语言创建进程用fork函数.fork就是从父进程拷贝一个新的进程出来,子进程 ...