一、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. 【转载】 tf.slice()介绍

    原文地址: https://blog.csdn.net/nini_coded/article/details/79852031 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议, ...

  2. 读论文《IMPALA: Scalable Distributed Deep-RL with Importance Weighted Actor-Learner Architectures》——(续)实验部分

    论文地址: https://arxiv.org/pdf/1802.01561v2.pdf 论文<IMPALA: Scalable Distributed Deep-RL with Importa ...

  3. Vector源码解读

    1.背景 阅读源码是提高编程技能的有效方式... 面试中也经常问到源码相关的问题..... 2.源码解读 在解读Vector时大家可以先解读ArrayList,因为这个两个的逻辑几乎是一样的.... ...

  4. JUC高并发编程(一)之请求合并案例

    1.背景 在做活动或者抢购场景,系统查询的请求并发量非常高 如果并发的访问数据库,会给数据库带来很大的压力, 这时候我们可以考虑将多个查询请求合并成一个查询请求返回给客户端, 比如:根据id查询爆款产 ...

  5. 与LLMs进行在IDE中直接、无需提示的交互是工具构建者探索的一个有希望的未来方向

    这个观点在卡内基梅隆大学与谷歌研究人员合作文章 <Using an LLM to Help With Code Understanding> 中提出. 论文地址:https://dl.ac ...

  6. RabbitMq高级特性之TTL 存活时间/过期时间 通俗易懂 超详细 【内含案例】

    RabbitMq高级特性之TTL 存活时间/过期时间 介绍 RabbitMQ支持消息的过期时间, 在消息发送时可以进行指定 RabbitMQ支持队列的过期时间, 从消息入队列开始计算, 只要超过了队列 ...

  7. CH03_运算符

    CH03_运算符 算术运算符 作用:用于处理四则运算 示例: #include <iostream> using namespace std; int main() { int a = 1 ...

  8. 【粉丝问答20】Linux内核定时器使用及其他时间操作

    问题描述 如何使用内核定时器? 内核定时器 Linux内核定时器是timer_list,下面我们详细介绍定时器的使用. 1. 简介 内核定时器是内核用来控制在未来某个时间点(基于jiffies)调度执 ...

  9. CentOs7.3 配置基本信息查看

    1.基本信息查看(命令行) [root@localhost home]# CPU个数: [root@localhost home]# grep 'physical id' /proc/cpuinfo ...

  10. 【音视频通话】使用asp.net core 8+vue3 实现高效音视频通话

    引言 在三年前,写智能小车的时候,当时小车上有一个摄像头需要采集,实现推拉流的操作,技术选型当时第一版用的是nginx的rtmp的推拉流,服务器的配置环境是centos,2H4G3M的一个配置,ngi ...