之前项目用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自动布局相关推荐

  1. iOS - Masonry自动布局

    简介: 相对于官方的NSLayoutConstraints的的过于繁琐和麻烦,Masonry是一个轻量级的布局框架 拥有自己的描述语法 采用更优雅的链式语法封装自动布局 简洁明了 并具有高可读性 而且 ...

  2. Masonry自动布局详解一:基本用法

    Masonry自动布局详解一:基本用法 说到iOS自动布局,有很多的解决办法.有的人使用xib/storyboard自动布局,也有人使用frame来适配.对于前者,笔者并不喜欢,也不支持.对于后者,更 ...

  3. Masonry自动布局详解五:比例(multipliedBy)

    Masonry自动布局详解五:比例(multipliedBy) 标签: iosmasonryautolayout自动布局约束 2015-11-30 16:30 1816人阅读 评论(0) 收藏 举报 ...

  4. iOS Masonry

    文章目录 Masonry简介 Masonry主要的类和常用api Masonry基本使用 Masonry结构与源码简单解析 Masonry使用技巧与注意事项 Masonry简介 Masonry利用简化 ...

  5. iOS Masonry 布局- UIScrollView/Masonry自动布局对UIScrollView的内容自适应

    2020年10月13日13:26:37「复习」 控制器中布局一般基础都是以UIscrollview为底部视图进行绘制的,方便我们进行屏幕适配. 在使用masonry布局的时候如何让UIscrollvi ...

  6. iOS Masonry的使用详解

    Masonry是一个轻量级的布局框架,拥有自己的描述语法,采用更优雅的链式语法封装自动布局,简洁明了并具有高可读性,而且同时支持 iOS 和 Max OS X.Masonry是一个用代码写iOS或OS ...

  7. 第三方库Masonry自动布局AutoLayout使用

    布局: 1. 放在哪  坐标  CGPoint(x, y)    2. 有多大  尺寸  CGSize(width, height) 布局方式: 1.绝对布局(FrameLayout)也称 坐标布局 ...

  8. iOS Masonry介绍与使用实践(快速上手Autolayout)

    前言 MagicNumber -> autoresizingMask -> autolayout 以上是纯手写代码所经历的关于页面布局的三个时期 在iphone1-iphone3gs时代 ...

  9. IOS Masonry介绍与使用实践:快速上手Autolayout

    转载大神:http://www.cocoachina.com/ios/20141219/10702.html 前言 MagicNumber -> autoresizingMask -> a ...

最新文章

  1. arcxml 中 outputmode=xml 和 outputmode=newxml 的区别
  2. GPU Gems翻译
  3. (JavaWeb)JSP,JSTL
  4. 前端学习(2354):image组件的基本使用
  5. 学成在线--11.RabbitMQ快速入门
  6. linux使用rsync增量保存文件与无交互自动传输
  7. javascript之继承
  8. 简单的Java服务器和客户端的通信
  9. 现在实体店的生意越来越不好干
  10. Silverlight访问WCF双工通信的官方例子
  11. Linux查看系统版本命令 linux学习教程
  12. Java下载base64图片
  13. 互联网晚报 | 12月7日 星期二 | 阿里新设两大数字商业板块;B站宣布迈入8K超高清时代;中国物流集团正式成立...
  14. mybatis插件破解
  15. HTML语言利用函数求中位数,Excel2013中通过if函数及median函数求得一组数据的中位数...
  16. 飞龙在天之DB面试资料
  17. 51系列单片机IO模试设置
  18. CAS号:60535-02-6,二肽Met-Trp
  19. 趣图 | 程序员的白天 vs 夜晚?
  20. java se7 if_Java SE7新特性之在数值型的字面值中使用下划线

热门文章

  1. Python OpenCV实例:图像重映射
  2. 手把手部署Linux下磁盘配额(quota)应用与实战
  3. C++:位操作基础篇之位操作全面总结
  4. Java 比较相等 == or .equal()?
  5. 把《c++ primer》读薄(4-2 c和c++的数组 和 指针初探)
  6. 使用Wine 1.6.2 在OS X El Capitan下运行Galgame
  7. Tornado 学习笔记
  8. Silverlight学习之——事件编程
  9. 打开word或者office程序报错:Microsoft Visual C++ Runtime Library. Runtime Error!
  10. maskrcnn用于目标检测_用于目标检测的池化渐进网络(Pooling Pyramid Network)