一:masonry 基本用法

    fistView=[[UIView alloc] init];
fistView.backgroundColor=[UIColor redColor];
[self.view addSubview:fistView]; secondView=[[UIView alloc] init];
secondView.backgroundColor=[UIColor blueColor];
[self.view addSubview:secondView]; threeView=[[UIView alloc] init];
threeView.backgroundColor=[UIColor yellowColor];
[self.view addSubview:threeView]; bottomView=[[UIView alloc] init];
bottomView.backgroundColor=[UIColor grayColor];
[self.view addSubview:bottomView];

基本约束布局代码

#pragma mark -第一种布局方法

-(void)left_top_size_marign{

    CGFloat padding =;
CGFloat width=(self.view.bounds.size.width-*padding)/; [fistView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(padding);
make.top.mas_equalTo(padding);
make.size.mas_equalTo(CGSizeMake(width, )); }]; [threeView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(padding*+width);
make.top.mas_equalTo(padding);
make.size.mas_equalTo(CGSizeMake(width, )); }]; [threeView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(padding*+width*);
make.top.mas_equalTo(padding);
make.size.mas_equalTo(CGSizeMake(width, )); }]; }

二:masonry 相对于子View布局

CGFloat padding =;
CGFloat width=(self.view.bounds.size.width-*padding)/; [fistView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(padding);
make.top.mas_equalTo(padding);
make.size.mas_equalTo(CGSizeMake(width, ));
}]; [secondView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(fistView.mas_right).offset(padding);
make.size.top.mas_equalTo(fistView); }]; [threeView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(secondView.mas_right).offset(padding);
make.size.top.mas_equalTo(secondView); }];

三:masonry内边距布局

//内边距
[paddingView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(fistView).insets(UIEdgeInsetsMake(, , , )); }];

四:UILable 多行布局

 lb=[[UILabel alloc] init];
lb.text=@"ication:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add remote-notification to the list of your supported";
[self.view addSubview:lb]; --------- //label多行
lb.preferredMaxLayoutWidth=self.view.width-; lb.numberOfLines=;
[lb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(bottomView.mas_bottom).offset();
make.left.mas_equalTo();
make.right.mas_equalTo(-); }];

五:masonry动画更新

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    if(flag){

        CGFloat padding =;
CGFloat width=(self.view.bounds.size.width-*padding)/; [fistView mas_updateConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(padding);
make.top.mas_equalTo(padding);
make.size.mas_equalTo(CGSizeMake(width, ));
}]; }
else{ [fistView mas_updateConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo();
make.top.mas_equalTo();
make.size.mas_equalTo(CGSizeMake(, ));
}];
} flag=!flag; [UIView animateWithDuration:0.25 animations:^{ // [self.view layoutIfNeeded]; } completion:^(BOOL finished) { }]; }

masonry 基本用法的更多相关文章

  1. Masonry基本用法

    使用步骤: 1.导入框架 2.导入头文件,或者直接导入.pch文件中 //省略前缀 'max_'的宏: #define MAS_SHORTHAND // 自动装箱:自动把基本数据类型转化成对象,int ...

  2. Autolayout 第三方开源库

    转载自:http://blog.csdn.net/hmt20130412/article/details/46638625 今天才发现CSDN支持markdown了…还是给出新博客地址:Autolay ...

  3. 关于Masonry框架(AutoLayout)的用法--面向初学者

    Masonry作为目前较为流行的自动布局第三方框架,简单易用,大大减少了程序员花在UI布局和屏幕适配的精力与时间. 1 基本用法 1.1 事例1: 图1-1 // 首先是view1自动布局 [view ...

  4. Masonry和FDTemplateLayoutCell 结合使用示例Demo

    我们知道,界面布局可以用Storyboard或Xib结合Autolayout实现,如果用纯代码布局,比较热门的有Masonry.SDAutoLayout,下面的简单demo,采用纯代码布局,实现不定高 ...

  5. Masonry tableviewCell布局(转)

    转载自:http://www.henishuo.com/masonry-tableviewcell-layout/ 前言 说到iOS自动布局,有很多的解决办法.有的人使用xib/storyboard自 ...

  6. 【原】iOS学习之Masonry第三方约束

    1.Masonry概述 目前最流行的Autolayout第三方框架 用优雅的代码方式编写Autolayout 省去了苹果官方恶心的Autolayout代码 大大提高了开发效率 框架地址:https:/ ...

  7. Coding源码学习第四部分(Masonry介绍与使用(三))

    接上篇继续进行Masonry 的学习. (12)tableViewCell 布局 #import "TableViewController.h" #import "Tes ...

  8. iOS自动布局进阶用法

    本文主要介绍几个我遇到并总结的相对高级的用法(当然啦牛人会觉得这也不算什么). 简单的storyboard中上下左右约束,固定宽高啥的用法在这里就不做赘述了. autolayout自动布局是iOS6以 ...

  9. Masonry学习分享

    不完整目录 •UIScrollView 应用Masonry的正确用法 •tableHeaderView使用Masonry •同向文字显示优先级 1.基础篇 1.1基础使用 1.1.1运行效果 1.1. ...

随机推荐

  1. B - Glider Gym - 101911B(二分)

    output standard output A plane is flying at a constant height of hh meters above the ground surface. ...

  2. POJ 1328 安装雷达 (贪心)

    <题目链接> 题目大意: 以x轴为分界,y>0部分为海,y<0部分为陆地,给出一些岛屿坐标(在海中),再给出雷达可达到范围,雷达只可以安在陆地上,问最少多少雷达可以覆盖所以岛屿 ...

  3. NIO缓冲区基本操作:rewind(),clear(),flip()

    rewind() rewind()方法将position置0,清除mark,它的作用在于为提取Buffer的有效数据做准备. ByteBuffer byteBuf = ByteBuffer.alloc ...

  4. CCF-学生排队

    PS:此文章已在我的站点更新,请移步访问~更多注释讲解哦.https://www.jeson.xin/ccf-student_queuing.html

  5. C# 中BindingSource 的用法

    .引言 BindingSource组件是数据源和控件间的一座桥,同时提供了大量的API和Event供我们使用.使用这些API我们可以将Code与各种具体类型数据源进行解耦:使用这些Event我们可以洞 ...

  6. Java笔记(五)泛型

    泛型 一.基本概念和原理 泛型将接口的概念进一步延申,“泛型”的字面意思是广泛的类型. 类.接口和方法都可以应用于非常广泛的类型,代码与它们能够操作 的数据类型不再绑定到一起,同一套代码可以应用到多种 ...

  7. spring 空指针报错,Could not create connection to database server.

    驱动问题,换成最近版本的mysql驱动

  8. ACM知识点总结

    1 枚举 2 模拟 3 构造 4 位运算的应用 5 查找 5.1 二分查找 5.2 分块查找 5.3 哈希查找HASH 5.3.1 线性探测法 5.3.2 字符串与哈希 6 搜索 6.1 深度优先搜索 ...

  9. 关于git的使用记录总结

    1.解决Windows下git换行符报警问题 git config --global core.autocrlf false 2.撤销add的文件退出暂存区 git reset --mixed 3.g ...

  10. Java中Iterator(迭代器)实现原理

    在Java中遍历List时会用到Java提供的Iterator,Iterator十分好用,原因是: 迭代器是一种设计模式,它是一个对象,它可以遍历并选择序列中的对象,而开发人员不需要了解该序列的底层结 ...