测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布日期上次发布 | 2015年5月 |
由 Daniel Bowden 维护。
一个 UITableViewCell 的子类,用于 iOS 7,帮助自动布局动态高度的表格视图。它使用了创建原型单元格,并使用 systemLayoutSizeFittingSize 将父视图调整为 UILayoutFittingCompressedSize 的方法来根据自动布局约束调整子视图的大小。而不是现在已弃用的旧方法(如 sizeWithFont 等)。
包含示例项目。克隆仓库,然后打开 "DBDynamicHeightTableCellDemo.xcworkspace"。
由 Orta Therox 在 Cocoapods 的 Pod5播客 - 第13集 中提到。
创建一个类似于示例的 DBDynamicHeightTableCell
子类(InfoCell.h/m/xib)。
实现抽象方法 - (void)populateWithObject:(id)object;
。这用于填充您的单元格视图。基本示例
- (void)populateWithObject:(id)object
{
self.headlineLabel.text = [object headline];
self.summaryLabel.text = [object summary];
}
您甚至可以使用格式化的字符串,不同的字体大小、颜色等。
- (void)populateWithObject:(id)object
{
NSAttributedString *attributedHeadline = [[NSAttributedString alloc] initWithString:[object headline] attributes:@{NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle), NSFontAttributeName: [UIFont boldSystemFontOfSize:16.0], NSForegroundColorAttributeName: [UIColor redColor]}];
NSAttributedString *attributedSummary = [[NSAttributedString alloc] initWithString:[object summary] attributes:@{NSFontAttributeName: [UIFont italicSystemFontOfSize:14.0]}];
self.headlineLabel.attributedText = attributedHeadline;
self.summaryLabel.attributedText = attributedSummary;
}
要引用您的单元格 xib,实现抽象方法 + (UINib *)nib;
。
+ (UINib *)nib
{
return [UINib nibWithNibName:@"InfoCell" bundle:nil];
}
为您的单元格中的子视图设置自动布局约束,以使其知道如何增长/收缩。
Daniel Bowden
DBDynamicHeightTableCell 可在 MIT 许可下使用。更多信息请查看 LICENSE 文件。