一: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. python自带线程池

    1. 注意: 导包是: from multiprocessing.pool import ThreadPool #线程池不在thrading中 2. 代码: from mutiprocessing.p ...

  2. Kafka命令行操作及常用API

    一.Kafka命令行操作 1.查看当前集群已存在的主题 bin/kafka-topic.sh --zookeeper hd09-01:2181 --list 2.创建主题 bin/kafka-topi ...

  3. Java 之 OOAD

    1.UML a.全称:统一建模语言 b.UML图:流程图.用例图.时序图.类图 c.接口与类之间——实现 d.对象与对象之间 ①泛化——在UML中不叫继承,而叫泛化 ②关联 依赖:use a 是一种弱 ...

  4. BZOJ 4260 Codechef REBXOR (区间异或和最值) (01字典树+DP)

    <题目链接> 题目大意:给定一个序列,现在求出两段不相交的区间异或和的最大值. 解题分析: 区间异或问题首先想到01字典树.利用前缀.后缀建树,并且利用异或的性质,相同的两个数异或变成0, ...

  5. css布局方式总结

    ### 居中布局 ### 一.水平居中 * 要求:子元素于父元素水平居中且其(子元素与父元素)宽度均可变. ```` javacript <div class="parent" ...

  6. [MongoDB] MongoDB管理:使用killOp干掉Long Running Operation

    http://www.mongoing.com/archives/2563 MongoDB提供了killOp请求,用于干掉运行时间很长的请求,killOp通常需要与currentOp组合起来使用:先根 ...

  7. Lock锁与Condition监视器(生产者与消费者)。

    /*生产者与消费者第二次敲,本人表示很郁闷,以后要经常读这个 * Condition 将Object类中的监视器(wait notify notifyAll)分解成不同的对象.例如condition_ ...

  8. Linux之Redis安装

    一.下载解压 1 2 3 4 ## 下载Redis wget http://download.redis.io/releases/redis-2.8.17.tar.gz ## 解压 tar zxvf ...

  9. POJ 水题(刷题)进阶

    转载请注明出处:優YoU http://blog.csdn.net/lyy289065406/article/details/6642573 部分解题报告添加新内容,除了原有的"大致题意&q ...

  10. python数据类型内置方法 字符串和列表

    1.字符串 内置方法操作# a = 'qqssf'#1. print(a[-1:]) #按索引取,正向从0开始,反向从-1开始# print(len(a)) #取长度# a = 'qqssf'# 2. ...