masonry 基本用法
一: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 基本用法的更多相关文章
- Masonry基本用法
使用步骤: 1.导入框架 2.导入头文件,或者直接导入.pch文件中 //省略前缀 'max_'的宏: #define MAS_SHORTHAND // 自动装箱:自动把基本数据类型转化成对象,int ...
- Autolayout 第三方开源库
转载自:http://blog.csdn.net/hmt20130412/article/details/46638625 今天才发现CSDN支持markdown了…还是给出新博客地址:Autolay ...
- 关于Masonry框架(AutoLayout)的用法--面向初学者
Masonry作为目前较为流行的自动布局第三方框架,简单易用,大大减少了程序员花在UI布局和屏幕适配的精力与时间. 1 基本用法 1.1 事例1: 图1-1 // 首先是view1自动布局 [view ...
- Masonry和FDTemplateLayoutCell 结合使用示例Demo
我们知道,界面布局可以用Storyboard或Xib结合Autolayout实现,如果用纯代码布局,比较热门的有Masonry.SDAutoLayout,下面的简单demo,采用纯代码布局,实现不定高 ...
- Masonry tableviewCell布局(转)
转载自:http://www.henishuo.com/masonry-tableviewcell-layout/ 前言 说到iOS自动布局,有很多的解决办法.有的人使用xib/storyboard自 ...
- 【原】iOS学习之Masonry第三方约束
1.Masonry概述 目前最流行的Autolayout第三方框架 用优雅的代码方式编写Autolayout 省去了苹果官方恶心的Autolayout代码 大大提高了开发效率 框架地址:https:/ ...
- Coding源码学习第四部分(Masonry介绍与使用(三))
接上篇继续进行Masonry 的学习. (12)tableViewCell 布局 #import "TableViewController.h" #import "Tes ...
- iOS自动布局进阶用法
本文主要介绍几个我遇到并总结的相对高级的用法(当然啦牛人会觉得这也不算什么). 简单的storyboard中上下左右约束,固定宽高啥的用法在这里就不做赘述了. autolayout自动布局是iOS6以 ...
- Masonry学习分享
不完整目录 •UIScrollView 应用Masonry的正确用法 •tableHeaderView使用Masonry •同向文字显示优先级 1.基础篇 1.1基础使用 1.1.1运行效果 1.1. ...
随机推荐
- thinkphp模板继承
public/base.html <!DOCTYPE html> <html lang="en"> <head> <meta charse ...
- POJ 3189 Steady Cow Assignment 【二分】+【多重匹配】
<题目链接> 题目大意: 有n头牛,m个牛棚,每个牛棚都有一定的容量(就是最多能装多少只牛),然后每只牛对每个牛棚的喜好度不同(就是所有牛圈在每个牛心中都有一个排名),然后要求所有的牛都进 ...
- Django初识 学习笔记一
Django初识 学习笔记一 mvcviewsmodelstemplate. 一 MVC框架 MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(c ...
- MVC面试问题与答案
读这篇文章不意味着你一定要去并且能搞定MVC面试.这篇文章的目的是在面试之前让你快速复习MVC知识.这篇文章也不是MVC培训课程. 如果你想学习MVC,从这儿开始 Learn MVC ( Model ...
- Java并发编程(六)-- 同步块
上一节已经讲到,使用Synchronzied代码块可以解决共享对象的竞争问题,其实还有其他的方法也可以避免资源竞争问题,我统称他们为Java同步块.Java 同步块(synchronized bloc ...
- [jzoj]1729.blockenemy
Link https://jzoj.net/senior/#main/show/1729 Description 你在玩电子游戏的时候遇到了麻烦...... 你玩的游戏是在一个虚拟的城市里进行,这个城 ...
- [jzoj]3521.道路覆盖(cover)
Link https://jzoj.net/senior/#main/show/3521 Description Tar把一段凹凸不平的路分成了高度不同的N段,并用H[i]表示第i段高度.现在Tar一 ...
- Flask实例化配置
template_folder :指定模板存放路径,默认值:temolates from flask import Flask, url_for app = Flask(__name__,templa ...
- bootcdn
BootCDN 是 Bootstrap 中文网支持并维护的前端开源项目免费 CDN 服务,致力于为 Bootstrap.jQuery.Angular.Vuejs 一样优秀的前端开源项目提供稳定.快速的 ...
- 删除office拥有多个都需要激活的授权信息
首先确认office目录下存在“ospp.vbs”文件,可以搜索确认文件路径. 我的是在C:\Program Files\Microsoft Office\Office16 然后以管理员身份打开cm ...