IOS Masonry自动布局

2024-02-28 15:18
文章标签 布局 自动 ios masonry

本文主要是介绍IOS Masonry自动布局,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

之前项目用Frame布局,这个项目登录用了VFL,后来觉得用Masonry,前天布局TableViewCell时用了下 ,觉得还不错。

#import "Masonry.h"
#import "MASViewAttribute.h"

先看效果图:

#import "ReportsCell.h"
//#import "Masonry.h"
#import "YZPUIFormatMacros.h"
#import "Global.h"static const CGFloat kIconWidth                 = 55.0f;
static const CGFloat kIconHeight                = 55.0f;@implementation ReportsCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];if (self) {self.backgroundColor = [UIColor whiteColor];UIView *headerView = [[UIView alloc]init];headerView.backgroundColor = YZPColorDividingLineOutdide;[self addSubview:headerView];[headerView mas_makeConstraints:^(MASConstraintMaker *make) {make.left.equalTo(@0);make.top.equalTo(@0);make.width.equalTo(@(MainWidth));make.height.equalTo(@(YZPSpaceHSmall));}];UIView *topLine=[self lineView];[headerView addSubview:topLine];[topLine mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(headerView.top);make.left.equalTo(headerView.left);make.width.equalTo(headerView.width);make.height.equalTo(@0.5);}];UIView *bottomLine=[self lineView];[headerView addSubview:bottomLine];[bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(headerView.bottom).with.offset(-0.5);make.left.equalTo(headerView.left);make.width.equalTo(headerView.width);make.height.equalTo(@0.5);}];_orderIdLabel=[[UILabel alloc]init];_orderIdLabel.font = YZPFontSubhead;_orderIdLabel.textColor = YZPColorTextSubhead;[self addSubview:_orderIdLabel];[_orderIdLabel mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(headerView.bottom).with.offset(15);make.left.equalTo(@10);make.width.equalTo(headerView.width);make.height.equalTo(@20);}];_orderIconView=[[UIImageView alloc]init];[self addSubview:_orderIconView];[_orderIconView makeConstraints:^(MASConstraintMaker *make) {make.left.equalTo(@15);make.top.equalTo(_orderIdLabel.bottom).with.offset(15);make.width.equalTo(@(kIconWidth));make.height.equalTo(@(kIconHeight));}];_orderTitleLabel=[[UILabel alloc]init];_orderTitleLabel.font=YZPFontSubhead;_orderTitleLabel.textColor=[UIColor colorWithRed:0.141f green:0.141f blue:0.141f alpha:1.00f];_orderTitleLabel.numberOfLines=2;[self addSubview:_orderTitleLabel];[_orderTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {make.left.equalTo(_orderIconView.right).with.offset(15);make.top.equalTo(_orderIconView.top).with.offset(2);make.width.equalTo(@(MainWidth-170));make.height.lessThanOrEqualTo(@(35));}];_orderSpecLabel=[[UILabel alloc]init];_orderSpecLabel.font=YZPFontExplain;_orderSpecLabel.textColor=[UIColor colorWithRed:0.400f green:0.400f blue:0.400f alpha:1.00f];[self addSubview:_orderSpecLabel];[_orderSpecLabel mas_makeConstraints:^(MASConstraintMaker *make) {make.left.equalTo(_orderTitleLabel.left);make.top.equalTo(_orderTitleLabel.bottom).offset(10);make.width.equalTo(@(MainWidth-135));make.height.lessThanOrEqualTo(@(20));}];_productsCountLabel=[[UILabel alloc]init];_productsCountLabel.font=YZPFontContent;_productsCountLabel.textAlignment=NSTextAlignmentRight;_productsCountLabel.textColor=[UIColor colorWithRed:0.400f green:0.400f blue:0.400f alpha:1.00f];[self addSubview:_productsCountLabel];[_productsCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(_orderTitleLabel.top);make.left.equalTo(_orderTitleLabel.right).offset(5);make.right.equalTo(self.right).with.offset(-15);make.height.equalTo(_orderTitleLabel.height);}];UIView *centerLine=[self lineView];[self addSubview:centerLine];[centerLine mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(_orderIconView.bottom).offset(15);make.left.equalTo(self);make.width.equalTo(self);make.height.equalTo(@0.5);}];_userNameLabel=[[UILabel alloc]init];_userNameLabel.font=YZPFontExplain;_userNameLabel.textColor=YZPColorTextExplain;
//        _userNameLabel.numberOfLines=2;_userNameLabel.textAlignment=NSTextAlignmentLeft;[self addSubview:_userNameLabel];[_userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {make.left.equalTo(self.left).with.offset(15);make.top.equalTo(centerLine.bottom).offset(10);make.width.lessThanOrEqualTo(@150);make.height.lessThanOrEqualTo(@35);}];_userPhoneLabel=[[UILabel alloc]init];_userPhoneLabel.font=YZPFontExplain;_userPhoneLabel.textColor=YZPColorTextExplain;_userPhoneLabel.textAlignment=NSTextAlignmentRight;[self addSubview:_userPhoneLabel];[_userPhoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(_userNameLabel.top);make.right.equalTo(self.right).with.offset(-15);make.height.lessThanOrEqualTo(@35);make.width.lessThanOrEqualTo(@150);}];_userAddressLabel=[[UILabel alloc]init];_userAddressLabel.font=YZPFontExplain;_userAddressLabel.textColor=YZPColorTextExplain;[self addSubview:_userAddressLabel];[_userAddressLabel mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(_userNameLabel.bottom).with.offset(10);make.left.equalTo(self.left).with.offset(15);
//            make.bottom.equalTo(self.bottom).with.offset(-10);make.width.equalTo(self.width);make.height.lessThanOrEqualTo(@35);}];}return self;
}
-(UIView *)lineView
{UIView *line=[[UIView alloc]init];
//    line.backgroundColor=[UIColor redColor];line.backgroundColor=[UIColor colorWithRed:0.800f green:0.800f blue:0.800f alpha:1.00f];return line;
}- (void)awakeFromNib {// Initialization code
}- (void)setSelected:(BOOL)selected animated:(BOOL)animated {[super setSelected:selected animated:animated];// Configure the view for the selected state
}@end


这篇关于IOS Masonry自动布局的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/755868

相关文章

Spring Boot项目中结合MyBatis实现MySQL的自动主从切换功能

《SpringBoot项目中结合MyBatis实现MySQL的自动主从切换功能》:本文主要介绍SpringBoot项目中结合MyBatis实现MySQL的自动主从切换功能,本文分步骤给大家介绍的... 目录原理解析1. mysql主从复制(Master-Slave Replication)2. 读写分离3.

微信公众号脚本-获取热搜自动新建草稿并发布文章

《微信公众号脚本-获取热搜自动新建草稿并发布文章》本来想写一个自动化发布微信公众号的小绿书的脚本,但是微信公众号官网没有小绿书的接口,那就写一个获取热搜微信普通文章的脚本吧,:本文主要介绍微信公众... 目录介绍思路前期准备环境要求获取接口token获取热搜获取热搜数据下载热搜图片给图片加上标题文字上传图片

SpringBoot中封装Cors自动配置方式

《SpringBoot中封装Cors自动配置方式》:本文主要介绍SpringBoot中封装Cors自动配置方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录SpringBoot封装Cors自动配置背景实现步骤1. 创建 GlobalCorsProperties

idea中创建新类时自动添加注释的实现

《idea中创建新类时自动添加注释的实现》在每次使用idea创建一个新类时,过了一段时间发现看不懂这个类是用来干嘛的,为了解决这个问题,我们可以设置在创建一个新类时自动添加注释,帮助我们理解这个类的用... 目录前言:详细操作:步骤一:点击上方的 文件(File),点击&nbmyHIgsp;设置(Setti

一文详解SQL Server如何跟踪自动统计信息更新

《一文详解SQLServer如何跟踪自动统计信息更新》SQLServer数据库中,我们都清楚统计信息对于优化器来说非常重要,所以本文就来和大家简单聊一聊SQLServer如何跟踪自动统计信息更新吧... SQL Server数据库中,我们都清楚统计信息对于优化器来说非常重要。一般情况下,我们会开启"自动更新

Flask 验证码自动生成的实现示例

《Flask验证码自动生成的实现示例》本文主要介绍了Flask验证码自动生成的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习... 目录生成图片以及结果处理验证码蓝图html页面展示想必验证码大家都有所了解,但是可以自己定义图片验证码

Python Excel实现自动添加编号

《PythonExcel实现自动添加编号》这篇文章主要为大家详细介绍了如何使用Python在Excel中实现自动添加编号效果,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1、背景介绍2、库的安装3、核心代码4、完整代码1、背景介绍简单的说,就是在Excel中有一列h=会有重复

Springboot的自动配置是什么及注意事项

《Springboot的自动配置是什么及注意事项》SpringBoot的自动配置(Auto-configuration)是指框架根据项目的依赖和应用程序的环境自动配置Spring应用上下文中的Bean... 目录核心概念:自动配置的关键特点:自动配置工作原理:示例:需要注意的点1.默认配置可能不适合所有场景

CSS3 最强二维布局系统之Grid 网格布局

《CSS3最强二维布局系统之Grid网格布局》CS3的Grid网格布局是目前最强的二维布局系统,可以同时对列和行进行处理,将网页划分成一个个网格,可以任意组合不同的网格,做出各种各样的布局,本文介... 深入学习 css3 目前最强大的布局系统 Grid 网格布局Grid 网格布局的基本认识Grid 网

Java中实现订单超时自动取消功能(最新推荐)

《Java中实现订单超时自动取消功能(最新推荐)》本文介绍了Java中实现订单超时自动取消功能的几种方法,包括定时任务、JDK延迟队列、Redis过期监听、Redisson分布式延迟队列、Rocket... 目录1、定时任务2、JDK延迟队列 DelayQueue(1)定义实现Delayed接口的实体类 (