美文网首页
Masonry的学习

Masonry的学习

作者: 乡村武装青年 | 来源:发表于2015-12-20 15:35 被阅读149次

Masonry是一个轻量级的布局框架  采用更优雅的链式语法封装自动布局简洁明了.

用masonry已经有一段时间,也就是停留在官方demo的事例基础上,今天有空就刚好研究一下zorro写的一个demo

子视图始终是父视图的一半改怎么写:

UIView*subView = [UIViewnew];

subView.backgroundColor= [UIColorredColor];

[_containerViewaddSubview:subView];

[subViewmas_makeConstraints:^(MASConstraintMaker*make) {

//上下左贴边

make.left.equalTo(_containerView.mas_left);

make.top.equalTo(_containerView.mas_top);

make.bottom.equalTo(_containerView.mas_bottom);

//宽度为父view的宽度的一半

make.width.equalTo(_containerView.mas_width).multipliedBy(0.5);

}];


tableviewcell高度根据内容自适应:

这里分为2种情况,ios8之后tableview有个新的特性可以计算cell内容返回高度:

// iOS 8的Self-sizing特性

if([UIDevice currentDevice].systemVersion.integerValue >7) {

_tableView.rowHeight = UITableViewAutomaticDimension;

}

或者用masonry计算cell高度

- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath {

#ifdef IOS_8_NEW_FEATURE_SELF_SIZING

// iOS 8的Self-sizing特性

return UITableViewAutomaticDimension;

#else

staticCase4Cell*templateCell;

staticdispatch_once_tonceToken;

dispatch_once(&onceToken, ^{

templateCell = [tableViewdequeueReusableCellWithIdentifier:NSStringFromClass([Case4Cellclass])];

});

//获取对应的数据

Case4DataEntity*dataEntity =_data[(NSUInteger) indexPath.row];

//判断高度是否已经计算过

if(dataEntity.cellHeight<=0) {

//填充数据

[templateCellsetupData:dataEntity];

//根据当前数据,计算Cell的高度,注意+1

dataEntity.cellHeight= [templateCell.contentViewsystemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height+0.5f;

NSLog(@"Calculate height: %ld", (long) indexPath.row);

}else{

NSLog(@"Get cache %ld", (long) indexPath.row);

}

returndataEntity.cellHeight;

#endif

}

相关文章

  • Masonry的学习

    Masonry是一个轻量级的布局框架 采用更优雅的链式语法封装自动布局简洁明了. 用masonry已经有一段时间,...

  • Masonry学习

    Masonry是一个轻量级的OC布局框架, 拥有自己的描述语法,采用更优雅的链式语法封装自动布局,简洁明了,并具有...

  • masonry学习

    如果不加入MAS_SHORTHAND_GLOBALS那么equalTo代表的是一个函数 这个函数还没有组装数据结构...

  • masonry学习

    使用: 1,先创建一个View 2,添加到父视图上 3,设置约束 4,创建了一个新的View,添加到上一个view...

  • Masonry 学习

    现在iPhone手机屏幕越来越多, 屏幕适配也越来越重要. Masonry就是为屏幕适配而生的三方框架. Maso...

  • iOS - Masonry使用中的一些整理

    [置顶]iOS - Masonry使用中的一些整理 标签:iOS资源大全iOS常用方法iOS学习资料Masonry...

  • iOS Autolayout之Masonry解读

    Masonry Masonry是公认非常简洁优美的一款Autolayout框架 我推荐大家重点学习这个框架 我会把...

  • Masonry 介绍 2018-01-29

    介绍 Masonry 源码:https://github.com/Masonry/Masonry Masonry是...

  • iOS框架·Masonry源码深度解析及学习启示:设计模式与链式

    传送门:链式编程小Demo 这篇文章是 Masonry 框架源码的解析和笔记。学习Masonry之前,先了解这个框...

  • iOS学习文章

    前言 收集一些学习的文章,以备查看 2015.12.21 NSURLSession 学习资源 Masonry 学习...

网友评论

      本文标题:Masonry的学习

      本文链接:https://www.haomeiwen.com/subject/ubhmhttx.html