一:masonry 基本用法

  1. fistView=[[UIView alloc] init];
  2. fistView.backgroundColor=[UIColor redColor];
  3. [self.view addSubview:fistView];
  4.  
  5. secondView=[[UIView alloc] init];
  6. secondView.backgroundColor=[UIColor blueColor];
  7. [self.view addSubview:secondView];
  8.  
  9. threeView=[[UIView alloc] init];
  10. threeView.backgroundColor=[UIColor yellowColor];
  11. [self.view addSubview:threeView];
  12.  
  13. bottomView=[[UIView alloc] init];
  14. bottomView.backgroundColor=[UIColor grayColor];
  15. [self.view addSubview:bottomView];

基本约束布局代码

  1. #pragma mark -第一种布局方法
  2.  
  3. -(void)left_top_size_marign{
  4.  
  5. CGFloat padding =;
  6. CGFloat width=(self.view.bounds.size.width-*padding)/;
  7.  
  8. [fistView mas_makeConstraints:^(MASConstraintMaker *make) {
  9.  
  10. make.left.mas_equalTo(padding);
  11. make.top.mas_equalTo(padding);
  12. make.size.mas_equalTo(CGSizeMake(width, ));
  13.  
  14. }];
  15.  
  16. [threeView mas_makeConstraints:^(MASConstraintMaker *make) {
  17.  
  18. make.left.mas_equalTo(padding*+width);
  19. make.top.mas_equalTo(padding);
  20. make.size.mas_equalTo(CGSizeMake(width, ));
  21.  
  22. }];
  23.  
  24. [threeView mas_makeConstraints:^(MASConstraintMaker *make) {
  25.  
  26. make.left.mas_equalTo(padding*+width*);
  27. make.top.mas_equalTo(padding);
  28. make.size.mas_equalTo(CGSizeMake(width, ));
  29.  
  30. }];
  31.  
  32. }

二:masonry 相对于子View布局

  1. CGFloat padding =;
  2. CGFloat width=(self.view.bounds.size.width-*padding)/;
  3.  
  4. [fistView mas_makeConstraints:^(MASConstraintMaker *make) {
  5. make.left.mas_equalTo(padding);
  6. make.top.mas_equalTo(padding);
  7. make.size.mas_equalTo(CGSizeMake(width, ));
  8. }];
  9.  
  10. [secondView mas_makeConstraints:^(MASConstraintMaker *make) {
  11. make.left.mas_equalTo(fistView.mas_right).offset(padding);
  12. make.size.top.mas_equalTo(fistView);
  13.  
  14. }];
  15.  
  16. [threeView mas_makeConstraints:^(MASConstraintMaker *make) {
  17. make.left.mas_equalTo(secondView.mas_right).offset(padding);
  18. make.size.top.mas_equalTo(secondView);
  19.  
  20. }];

三:masonry内边距布局

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

四:UILable 多行布局

  1. lb=[[UILabel alloc] init];
  2. lb.text=@"ication:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add remote-notification to the list of your supported";
  3. [self.view addSubview:lb];
  4.  
  5. ---------
  6.  
  7. //label多行
  8. lb.preferredMaxLayoutWidth=self.view.width-;
  9.  
  10. lb.numberOfLines=;
  11. [lb mas_makeConstraints:^(MASConstraintMaker *make) {
  12.  
  13. make.top.mas_equalTo(bottomView.mas_bottom).offset();
  14. make.left.mas_equalTo();
  15. make.right.mas_equalTo(-);
  16.  
  17. }];

五:masonry动画更新

  1. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  2.  
  3. if(flag){
  4.  
  5. CGFloat padding =;
  6. CGFloat width=(self.view.bounds.size.width-*padding)/;
  7.  
  8. [fistView mas_updateConstraints:^(MASConstraintMaker *make) {
  9. make.left.mas_equalTo(padding);
  10. make.top.mas_equalTo(padding);
  11. make.size.mas_equalTo(CGSizeMake(width, ));
  12. }];
  13.  
  14. }
  15. else{
  16.  
  17. [fistView mas_updateConstraints:^(MASConstraintMaker *make) {
  18. make.left.mas_equalTo();
  19. make.top.mas_equalTo();
  20. make.size.mas_equalTo(CGSizeMake(, ));
  21. }];
  22. }
  23.  
  24. flag=!flag;
  25.  
  26. [UIView animateWithDuration:0.25 animations:^{
  27.  
  28. // [self.view layoutIfNeeded];
  29.  
  30. } completion:^(BOOL finished) {
  31.  
  32. }];
  33.  
  34. }

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. thinkphp模板继承

    public/base.html <!DOCTYPE html> <html lang="en"> <head> <meta charse ...

  2. POJ 3189 Steady Cow Assignment 【二分】+【多重匹配】

    <题目链接> 题目大意: 有n头牛,m个牛棚,每个牛棚都有一定的容量(就是最多能装多少只牛),然后每只牛对每个牛棚的喜好度不同(就是所有牛圈在每个牛心中都有一个排名),然后要求所有的牛都进 ...

  3. Django初识 学习笔记一

    Django初识 学习笔记一 mvcviewsmodelstemplate. 一 MVC框架 MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(c ...

  4. MVC面试问题与答案

    读这篇文章不意味着你一定要去并且能搞定MVC面试.这篇文章的目的是在面试之前让你快速复习MVC知识.这篇文章也不是MVC培训课程. 如果你想学习MVC,从这儿开始 Learn MVC ( Model ...

  5. Java并发编程(六)-- 同步块

    上一节已经讲到,使用Synchronzied代码块可以解决共享对象的竞争问题,其实还有其他的方法也可以避免资源竞争问题,我统称他们为Java同步块.Java 同步块(synchronized bloc ...

  6. [jzoj]1729.blockenemy

    Link https://jzoj.net/senior/#main/show/1729 Description 你在玩电子游戏的时候遇到了麻烦...... 你玩的游戏是在一个虚拟的城市里进行,这个城 ...

  7. [jzoj]3521.道路覆盖(cover)

    Link https://jzoj.net/senior/#main/show/3521 Description Tar把一段凹凸不平的路分成了高度不同的N段,并用H[i]表示第i段高度.现在Tar一 ...

  8. Flask实例化配置

    template_folder :指定模板存放路径,默认值:temolates from flask import Flask, url_for app = Flask(__name__,templa ...

  9. bootcdn

    BootCDN 是 Bootstrap 中文网支持并维护的前端开源项目免费 CDN 服务,致力于为 Bootstrap.jQuery.Angular.Vuejs 一样优秀的前端开源项目提供稳定.快速的 ...

  10. 删除office拥有多个都需要激活的授权信息

    首先确认office目录下存在“ospp.vbs”文件,可以搜索确认文件路径. 我的是在C:\Program Files\Microsoft Office\Office16  然后以管理员身份打开cm ...