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(@);
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 Masonry自动布局的更多相关文章
- iOS masonry 不规则tagView布局 并自适应高度
在搜索页面经常会有不规则的tag出现,这种tagView要有点击事件,单个tagView可以设置文字颜色,宽度不固定根据内容自适应,高度固定,数量不固定.总高度就不固定.最近对于masonry的使用又 ...
- iOS AutoLayout自动布局&Masonry介绍与使用实践
Masonry介绍与使用实践:快速上手Autolayout http://www.cnblogs.com/xiaofeixiang/p/5127825.html http://www.cocoachi ...
- iOS SnapKit自动布局使用详解(Swift版Masonry)
对于自动布局: 我们在 StoryBoard 中可以使用约束实现,简单明了,但如果用纯代码来设置约束就很麻烦了 OC里面,我们常用的有Masonry,SDAutoLayout Swift里,我们有Sn ...
- ios - masonry第三方库使用自动布局(参考:http://www.cocoachina.com/ios/20141219/10702.html)
#import "ViewController.h" #import "Masonry.h" #define kWeakSelf(weakSelf) __wea ...
- 【iOS】Masonry 自动布局 MASViewConstraint.m:207 错误
问题详情: Assertion failure 报错原因: make.right.equalTo([_imageView superview]).right.with.offset(-); make. ...
- Masonry自动布局
介绍,入门: http://www.cocoachina.com/ios/20141219/10702.html 下载: http://code.cocoachina.com/detail/30114 ...
- iOS开发-自动布局篇:史上最牛的自动布局教学!
转载自:http://www.jianshu.com/p/f6cf9ef451d9 本文我们将提到: aotulayout(手码) VFL aotulayout(Xib) Masonry(第三方框架) ...
- iOS masonry九宫格 单行 多行布局
Masonry是个好东西,在当前尺寸各异的iOS开发适配中发挥着至关重要的作用,由于项目中Masonry布局用的比较多,对于UI布局也有了一些自己的理解,经常会有人问道Masonry布局九宫格要怎么布 ...
- Masonry自动布局使用
Masonry是一个轻量级的布局框架,采用更好的语法封装自动布局,它有自己的布局DSL.简洁明了并具有高可读性 而且同时支持 iOS 和 Max OS X. 下载 NSLayoutConstraint ...
随机推荐
- Spring中 使用注解+c3p0+事物 《模拟银行转账》
使用注解的方式 模拟转账 要么都成功 要么都失败 !保持一致性! 准备工作: jar包: 需要的类: UserDao: package com.hxzy.spring.c3p0.Dao ...
- vue 生命周期 笔记
生命周期:一个组件从创建到销毁的这个过程叫做生命周期 生命周期钩子函数 1.组件从创建到销毁的过程 1.创建前 创建后 2.挂载前 挂载后 3.更新前 更新后 4.销毁前 销毁后 beforeCr ...
- ie 8及以下 前端cors ajax跨域须知
http://www.cnblogs.com/xishuai/p/jquery-ajax-ie8-cors.html
- idea 新建New Module时Maven的列表加载不出来
Under Build → Build Tools → Maven → Importing, set VM options for importer to -Xmx1024m (the default ...
- AngularJS入门讲解1:angular基本概念
AngularJS应用程序主要有三个组成部分: 模板(Templates) 模板是您用HTML和CSS编写的文件,展现应用的视图. 您可给HTML添加新的元素.属性标记,作为AngularJS编译器的 ...
- 使用Python Pandas处理亿级数据
在数据分析领域,最热门的莫过于Python和R语言,此前有一篇文章<别老扯什么Hadoop了,你的数据根本不够大>指出:只有在超过5TB数据量的规模下,Hadoop才是一个合理的技术选择. ...
- django model改变后,同步数据库
在使用django进行开发时,往往需要根据不同的需求对model进行更改.而这时候,python manage.py syncdb就不好使了. 目前有个很好的工具,是south,这个是专门用来更改mo ...
- 将参数传递给ASP.NET Core 2.0中的中间件
问题 在ASP.NET Core的安装过程中,如何将参数传递给中间件? 解 在一个空的项目中添加一个POCO类来保存中间件的参数, publicclass GreetingOptions { publ ...
- P1091 合唱队列
合唱队列 原题:传送门 核心代码: /* 方法求出每一个点的最长升子序列和最长降子序列,再加到该点上 通过循环比较哪个点最大,再用总长减去该点长度即是答案 */ #include<iostrea ...
- js数字格式化为千分位
方法1: 浏览器自带的一个方法 const num=12345.6789 num.toLocaleString();=>"12,345.679" 方法2: 正则匹配 func ...