之前项目用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自动布局的更多相关文章

  1. iOS masonry 不规则tagView布局 并自适应高度

    在搜索页面经常会有不规则的tag出现,这种tagView要有点击事件,单个tagView可以设置文字颜色,宽度不固定根据内容自适应,高度固定,数量不固定.总高度就不固定.最近对于masonry的使用又 ...

  2. iOS AutoLayout自动布局&Masonry介绍与使用实践

    Masonry介绍与使用实践:快速上手Autolayout http://www.cnblogs.com/xiaofeixiang/p/5127825.html http://www.cocoachi ...

  3. iOS SnapKit自动布局使用详解(Swift版Masonry)

    对于自动布局: 我们在 StoryBoard 中可以使用约束实现,简单明了,但如果用纯代码来设置约束就很麻烦了 OC里面,我们常用的有Masonry,SDAutoLayout Swift里,我们有Sn ...

  4. ios - masonry第三方库使用自动布局(参考:http://www.cocoachina.com/ios/20141219/10702.html)

    #import "ViewController.h" #import "Masonry.h" #define kWeakSelf(weakSelf) __wea ...

  5. 【iOS】Masonry 自动布局 MASViewConstraint.m:207 错误

    问题详情: Assertion failure 报错原因: make.right.equalTo([_imageView superview]).right.with.offset(-); make. ...

  6. Masonry自动布局

    介绍,入门: http://www.cocoachina.com/ios/20141219/10702.html 下载: http://code.cocoachina.com/detail/30114 ...

  7. iOS开发-自动布局篇:史上最牛的自动布局教学!

    转载自:http://www.jianshu.com/p/f6cf9ef451d9 本文我们将提到: aotulayout(手码) VFL aotulayout(Xib) Masonry(第三方框架) ...

  8. iOS masonry九宫格 单行 多行布局

    Masonry是个好东西,在当前尺寸各异的iOS开发适配中发挥着至关重要的作用,由于项目中Masonry布局用的比较多,对于UI布局也有了一些自己的理解,经常会有人问道Masonry布局九宫格要怎么布 ...

  9. Masonry自动布局使用

    Masonry是一个轻量级的布局框架,采用更好的语法封装自动布局,它有自己的布局DSL.简洁明了并具有高可读性 而且同时支持 iOS 和 Max OS X. 下载 NSLayoutConstraint ...

随机推荐

  1. zTree设置选中节点之后出现重复节点

    1.用户离开页面时最后一次点击的节点信息我会保存到数据库. 2.用户打开页面时默认选中上一次离开时选中的节点. 现在发现在设置选中节点之后,会出现重复的节点(重复现象偶尔出现). 以下是代码: var ...

  2. sqlcmd 执行SQL语句或没有足够的内存来执行脚本

    win+r命令提示框里面输入cmd sqlcmd -S . -U username -P password -d database -i url -S 数据库地址 -U 登录名称 -P 密码 -d 数 ...

  3. LightOJ 1213 Fantasy of a Summation(规律 + 快数幂)

    http://lightoj.com/volume_showproblem.php?problem=1213  Fantasy of a Summation Time Limit:2000MS     ...

  4. ANE-如何加入ane,调试时又不报错

    有时候我们加入ane,即使没有调用ane的功能,debug的时候也会报错无法调试,这是为什么呢?因为我们的ane没有把default包含进去. 首先我们的extension.xml要把default节 ...

  5. JAVA特性一:封装

    封装:是指隐藏对象的属性和实现细节,仅对外提供公共访问方式. 封装概念详解:封装是把过程和数据包围起来,对数据的访问只能通过已定义的接口. 面向对象计算始于这个基本概念,即现实世界可以被描绘成一系列完 ...

  6. docker启动时报错

    docker安装成功后,启动时报错. 1.后来排查后发现yum install docker安装的是从test存储库中安装的. 后来我指定了特定的版本后,而且从stable存储库安装的,以后再启动就好 ...

  7. 洛谷P3676 小清新数据结构题(动态点分治+树链剖分)

    传送门 感觉这题做下来心态有点崩……$RMQ$求$LCA$没有树剖快我可以理解为是常数太大……然而我明明用了自以为不会退化的点分然而为什么比会退化的点分跑得反而更慢啊啊啊啊~~~ 先膜一波zsy大佬 ...

  8. windows环境下ElasticSearch5以上版本安装head插件

    我的ElasticSearch版本是5以上的,网上搜了好多安装方式,都不对. 还好找到一个成功的,转载过来做记录. 原文地址:ElasticSearch-5.0安装head插件 步骤 下载node.j ...

  9. [javascript]——将变量转化为字符串

    这是一个非常常用,但是我自己却经常忘记的一个方法: var item = 'textssdf'; console.log("'"+item+"'") > ...

  10. 常用的PHP超全局变量$_SERVER 收集整理

    传送带:https://www.cnblogs.com/rendd/p/6182918.html