Masonry与UITableView+FDTemplateLayoutCell搭配使用

之前发过一篇博客,也是对这两个的练习使用,但是之后遇到些问题,所以删除重写了。抱歉

Masonry是一款轻量级的布局框架,上手简单。本文只是对此的基本使用,具体可看以下两篇技术博客:

iOS 源代码分析----Masonry:http://draveness.me/ios-yuan-dai-ma-fen-xi-masonry/

Masonry介绍与使用实践(快速上手Autolayout):http://adad184.com/2014/09/28/use-masonry-to-quick-solve-autolayout/

Masonry的github链接:https://github.com/SnapKit/Masonry

UITableView-FDTemplateLayoutCell github:https://github.com/forkingdog/UITableView-FDTemplateLayoutCell

进入正题:(本文素材是来自阳神的demo里面的。阳神用的是storyboard实现,而我是用Masonry实现)

1.首先在子线程解析JSON数据

Masonry与UITableView+FDTemplateLayoutCell搭配使用

 

2.然后返回主线程注册cell,并且刷新tableView

Masonry与UITableView+FDTemplateLayoutCell搭配使用

3.在cellForRowAtIndexPath的方法中抽出一个方法,给cell的模型赋值。

UITableView+FDTemplateLayoutCell 这个类有两种模式,一种是使用自动布局,一种则是计算frame的形式。

Masonry与UITableView+FDTemplateLayoutCell搭配使用

4.接下来我们看下自定义cell里面的实现。

在初始化的方法内部创建子控件并且使用Masonry布局

Masonry与UITableView+FDTemplateLayoutCell搭配使用

5.布局方法实现

Masonry与UITableView+FDTemplateLayoutCell搭配使用

6.当你是使用计算frame模式的时候,需要在cell里面实现sizeThatFits这个方法

Masonry与UITableView+FDTemplateLayoutCell搭配使用

 

7.重新返回控制器中,实现tableview的heightForRowAtIndexPath方法,在其内部重新给cell的模型赋值

Masonry与UITableView+FDTemplateLayoutCell搭配使用

 

 

Demo截图:

Masonry与UITableView+FDTemplateLayoutCell搭配使用Masonry与UITableView+FDTemplateLayoutCell搭配使用

 

本文Demo地址:https://github.com/XQBoy/MasonryExercise

以后 会将每学到一个框架的基本使用都会尝试写博客上来,希望大家多多支持,谢谢

PS:小广告~

iOS交流群:248458280

有兴趣的可以进,大伙一起相互学习~

相关文章:

  • 2022-12-23
  • 2021-07-22
  • 2022-03-03
  • 2021-11-23
  • 2021-11-11
  • 2022-01-25
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
  • 2022-12-23
相关资源
相似解决方案