一: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. 斐波那契数列-java编程:三种方法实现斐波那契数列

    题目要求:编写程序在控制台输出斐波那契数列前20项,每输出5个数换行 斐波那契数列指的是这样一个数列:1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, … 这个数列 ...

  2. Codeforces 861D - Polycarp's phone book 【Trie树】

    <题目链接> 题目大意: 输入7e4个长度为9的字符串,每个字符串中只出现0~9这几种数字,现在需要你输出每个母串中最短的特有子串. 解题分析: 利用Trie树进行公共子串的判定,因为Tr ...

  3. 001.Redis简介及安装

    一 Redis简介 1.1 Redis 简介 Redis 是完全开源免费的,遵守BSD协议,是一个高性能的key-value数据库. Redis 与其他 key-value 缓存产品有以下三个特点: ...

  4. Kafka、RabbitMQ、RocketMQ等消息中间件的对比 —— 消息发送性能和区别

    https://blog.csdn.net/yunfeng482/article/details/72856762

  5. linux 学习笔记 tail 命令

    #tail -f -n 100 catalina.out 含义:从文件尾部监视catalina.out文件  主要看尾部100行 #tail -f -n 100 catalina.out > n ...

  6. Xamarin Essentials教程安全存储SecureStorage

    Xamarin Essentials教程安全存储SecureStorage   在实际应用中,应用程序会将一些数据保存在用户设备中,避免用户重复操作.但是为了防止因设备丢失或者感染病毒导致数据泄漏,需 ...

  7. [NOIp2018提高组]货币系统

    [NOIp2018提高组]货币系统 题目大意: 有\(n(n\le100)\)种不同的货币,每种货币的面额为\([1,25000]\)之间的一个整数.若两种货币系统能够组合出来的数是相同的的,那我们就 ...

  8. Linux 压缩解压缩

    先直接给出各种解压缩命令 .tar 压缩:tar cvf FileName.tar FileName 解压:tar xvf FileName.tar ------------------------- ...

  9. Node_初步了解(4)小爬虫

    var http=require('http'); var cheerio=require('cheerio'); var url='http://www.cnblogs.com/Lwd-linux/ ...

  10. J - 青蛙的约会(扩展欧几里得)

    https://vjudge.net/contest/218366#problem/J 第一步追及公式要写对:y+nk-(x+mk)=pL => (n-m)k+lp=x-y 可以看出扩展欧几里得 ...