IOS Masonry自动布局
2024-08-28 19:23:28
之前项目用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(@); make.top.equalTo(@); 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(); make.left.equalTo(@); make.width.equalTo(headerView.width); make.height.equalTo(@); }]; _orderIconView=[[UIImageView alloc]init]; [self addSubview:_orderIconView]; [_orderIconView makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(@); make.top.equalTo(_orderIdLabel.bottom).with.offset(); 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=; [self addSubview:_orderTitleLabel]; [_orderTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(_orderIconView.right).with.offset(); make.top.equalTo(_orderIconView.top).with.offset(); make.width.equalTo(@(MainWidth-)); make.height.lessThanOrEqualTo(@()); }]; _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(); make.width.equalTo(@(MainWidth-)); make.height.lessThanOrEqualTo(@()); }]; _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(); make.right.equalTo(self.right).with.offset(-); make.height.equalTo(_orderTitleLabel.height); }]; UIView *centerLine=[self lineView]; [self addSubview:centerLine]; [centerLine mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(_orderIconView.bottom).offset(); 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(); make.top.equalTo(centerLine.bottom).offset(); make.width.lessThanOrEqualTo(@); make.height.lessThanOrEqualTo(@); }]; _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(-); make.height.lessThanOrEqualTo(@); make.width.lessThanOrEqualTo(@); }]; _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(); make.left.equalTo(self.left).with.offset(); // make.bottom.equalTo(self.bottom).with.offset(-10); make.width.equalTo(self.width); make.height.lessThanOrEqualTo(@); }]; } 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中常用的宏定义
- 建表and新增删除数据A
- VMware桥接模式无法自动化获取IP的解决方法
- python验证登录
- ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布局
- VirtualBox – Error In supR3HardenedWinReSpawn 问题解决办法
- BZOJ 4011 落忆枫音
- Spring 中jdbcTemplate 实现执行多条sql语句
- JavaScript高级程序设计50.pdf
- Java中重载和重写的区别
- CSS3 &; SVG 制作钟表
- Message:Unable to locate element 问题解决方法
- 网络基础二 tcp/ip协议簇 端口 三次握手 四次挥手 11种状态集
- C语言--第2次作业
- 《R语言入门与实践》第七章:程序
- linux常用命令简介
- casbin的分析
- python3 fileinput模块
- 数据库使用SSIS进行数据清洗教程
- Wide - Residual - Inception Networks for R eal - time O bject D etection
热门文章
- (zxing.net)一维码Code 128的简介、实现与解码
- C#基础知识入门概要(自我回顾用)
- C#List的创建例程
- 考取RHCE认证的历程,总结的经验
- 【OCP-12c】2019年CUUG OCP 071考试题库(73题)
- TortoiseGit revert failed - unable to revert local changes
- php socket 简单理解
- 关于IPv4设置一些常见问题的解答
- RHEL安装oracle客户端(版本为11.2)
- day 28 :进程相关,进程池,锁,队列,生产者消费者模式