CocoaPods trunk is moving to be read-only. Read more on the blog, there are 19 months to go.
TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2017 |
Maintained by asiosldh.
对
UITableView
之Cell
和UITableViewHeaderFooterView
高度自适应并缓存,同时完美支持Storyboard
、Xib
、Masonry
,及注册方式
或者alloc方式
创建Cell
此库代码参考了FDTemplateLayoutCell在此感谢。
由于最近需要做一个类似微信聊天窗口的功能,牵涉到
UITableViewCell
的高度自适应,同时需要准确获取UITableView
的contentSize
并做相应的滚动和动画,在反复尝试使用系统自适应和FDTemplateLayoutCell均有一些小问题待处理,代码计算又太麻烦,故尝试自己实现。
contentSize
。iOS10.2.1
会崩溃,而且好像有一些小问题。注意:
BMTemplateLayoutCell的实现原理是:内部创建Cell,然后使用Block让外部进行设值和布局,内部在使用 layoutIfNeeded 强制布局,在获取Cell的contentView的最底部的View的最大高度为Cell需要的高度,所以使用者不可对您自定义的Cell设置任何的底部约束限制,所以可能需要您额外增加一个View(记住把它的高度最好设置为0,它的唯一功能是提供布局需要),直接由顶部布局下来即可,放心内部会处理好的
在
Cell
中必须保证有一个视图的最大Y
即是Cell
的高度,具体可以查看demo
中的xib
约束设置。
xib
masonry
注册方式
和alloc方式
创建Cell
TableView
支持横竖屏请设置以下属性为YES
,支持IB
和代码设置。@property (assign, nonatomic, getter=isScreenRotating) IBInspectable BOOL screenRotating; ///< 是否支持屏幕旋转,默认NO
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
BMModel *model = self.dataArray[indexPath.row];
return [tableView bm_heightForCellWithCellClass:BMCell.class cacheByKey:model.ID configuration:^(__kindof BMCell *cell) {
cell.model = model;
}];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
BMModel *model = self.dataArray[section];
return [tableView bm_heightForHeaderFooterViewWithWithHeaderFooterViewClass:BMXibHeader.class cacheByKey:model.ID configuration:^(__kindof BMXibHeader *headerFooterView) {
headerFooterView.model = model;
}];
}
Podfile
中添加 `pod 'BMTemplateLayoutCell'pod install
或 pod update
#import <BMTemplateLayoutCell/UITableView+BMTemplateLayoutCell.h>
pod
无法找到 BMTemplateLayoutCell
可用 pod setup
或 rm ~/Library/Caches/CocoaPods/search_index.json
在 pod search BMTemplateLayoutCell
Clone
或者 download
下载BMTemplateLayoutCell
文件夹内的所有内容。BMTemplateLayoutCell
内的源文件添加(拖放)到你的工程。"UITableView+BMTemplateLayoutCell.h"
BMDragCellCollectionView
使用 MIT 许可证,详情可见 LICENSE 文件