一: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. Codeforces gym 101291 M (最长交替子序列)【DP】

    <题目链接> 题目大意:给你一段序列,要求你求出该序列的最长交替子序列,所谓最长交替子序列就是,这段序列的相邻三项必须是先递增再递减或者先递减再递增这样交替下去. 解题分析: 这与一道dp ...

  2. Effective Java 第三版——59. 熟悉并使用Java类库

    Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...

  3. AngularJS的Scope和Digest

    Angular是一个成熟和强大的JavaScript框架.它也是一个比较庞大的框架,在熟练掌握之前,需要领会它提出的很多新概念.很多Web开发人员涌向Angular,有不少人面临同样的障碍.Diges ...

  4. 移动端滑屏全应用【三】requestAnimationFrame的兼容与使用

    首先,传统做动画的方式有以下几种: 1. css的transition过度动画 2. css的animation动画 3. 使用setTimeout或setInterval模拟动画贞(js执行机制决定 ...

  5. springboot整合视图层之jsp

    在springboot中不推荐视图层使用jsp展示,但是人们以前已经习惯使用jsp,所以对jsp也有支持,但是是解耦性的.也就是说并没有像其他组件一样直接集成到启动器中,所以像jsp引擎之类的需要额外 ...

  6. ubantu中搭建virtualenv+python3.4+flask

    上一篇文章是基于ubantu14.04自带的Python2.7搭建的virtualenv+python+flask(需要特别注意文件夹是中文的问题),今天忙碌了三个小时,在网上大量查阅资料完成了vir ...

  7. POJ 1230 Pass-Muraille

    #include<iostream> #include<cstring> using namespace std; ; //(x,y) (x1,y1)墙的两个端点,所有墙最大列 ...

  8. 给有C或C++基础的Python入门 :Python Crash Course 4 操作列表 4.4 -- 4.5

    上接前一篇文章. 4.4 使用列表的一部分 一,切片 切边,顾名思义,就是处理列表的部分元素. 我们可以联系一下C++的一段语句:for(int i = 0; i < n-2; ++i) cou ...

  9. Java代码优化小结(一)

    (1)尽量指定类.方法的final修饰符 带有final修饰符的类是不可派生的.在Java核心API中,有许多应用final的例子,例如java.lang.String,整个类都是final的.为类指 ...

  10. JavaScript基础笔记(一)基本概念

    基本概念 一.语法 一)区分大小写 二)标识符 书写规则同Java 三)注释 略 四)严格模式 1.在整个脚本中启用严格模式:在顶部添加 "use strict" 2.指定函数在严 ...