博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
masonry 基本用法
阅读量:6498 次
发布时间:2019-06-24

本文共 3710 字,大约阅读时间需要 12 分钟。

一: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 =10;    CGFloat width=(self.view.bounds.size.width-4*padding)/3;        [fistView mas_makeConstraints:^(MASConstraintMaker *make) {            make.left.mas_equalTo(padding);        make.top.mas_equalTo(padding);        make.size.mas_equalTo(CGSizeMake(width, 100));            }];    [threeView mas_makeConstraints:^(MASConstraintMaker *make) {                make.left.mas_equalTo(padding*2+width);        make.top.mas_equalTo(padding);        make.size.mas_equalTo(CGSizeMake(width, 100));            }];            [threeView mas_makeConstraints:^(MASConstraintMaker *make) {                make.left.mas_equalTo(padding*3+width*2);        make.top.mas_equalTo(padding);        make.size.mas_equalTo(CGSizeMake(width, 100));            }];            }

 

二:masonry 相对于子View布局

CGFloat padding =10;    CGFloat width=(self.view.bounds.size.width-4*padding)/3;        [fistView mas_makeConstraints:^(MASConstraintMaker *make) {        make.left.mas_equalTo(padding);        make.top.mas_equalTo(padding);        make.size.mas_equalTo(CGSizeMake(width, 100));    }];        [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(5, 5, 5, 5));            }];

 

四: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-20;        lb.numberOfLines=0;    [lb mas_makeConstraints:^(MASConstraintMaker *make) {               make.top.mas_equalTo(bottomView.mas_bottom).offset(5);        make.left.mas_equalTo(10);        make.right.mas_equalTo(-10);                            }];

 五:masonry动画更新

-(void)touchesBegan:(NSSet
*)touches withEvent:(UIEvent *)event{ if(flag){ CGFloat padding =10; CGFloat width=(self.view.bounds.size.width-4*padding)/3; [fistView mas_updateConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(padding); make.top.mas_equalTo(padding); make.size.mas_equalTo(CGSizeMake(width, 100)); }]; } else{ [fistView mas_updateConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(5); make.top.mas_equalTo(5); make.size.mas_equalTo(CGSizeMake(200, 200)); }]; } flag=!flag; [UIView animateWithDuration:0.25 animations:^{ // [self.view layoutIfNeeded]; } completion:^(BOOL finished) { }]; }

 

转载于:https://www.cnblogs.com/gcb999/p/7047727.html

你可能感兴趣的文章
masonry 基本用法
查看>>
使用openssl创建自签名证书及部署到IIS教程
查看>>
Word产品需求文档,已经过时了【转】
查看>>
dtoj#4299. 图(graph)
查看>>
关于网站的一些js和css常见问题的记录
查看>>
zabbix-3.4 触发器
查看>>
换用代理IP的Webbrowser方法
查看>>
【视频编解码·学习笔记】7. 熵编码算法:基础知识 & 哈夫曼编码
查看>>
spark集群安装部署
查看>>
MySql 查询表字段数
查看>>
mariadb 内存占用优化
查看>>
Centos7安装编译安装zabbix2.219及mariadb-5.5.46
查看>>
Visual Studio Remote Debugger(for 2005/2008) .net远程调试<转>
查看>>
怎么获得combobox的valueField值
查看>>
浅谈C/C++中的static和extern关键字
查看>>
Console-算法[if,while]-一输入两个正整数m和n,求其最大公约数和最小公倍数
查看>>
浅谈网络协议(四) IP的由来--DHCP与PXE
查看>>
jre与jdk的区别
查看>>
全景图的种类
查看>>
git 维护
查看>>