DBDynamicHeightTableCell 0.1.1

DBDynamicHeightTableCell 0.1.1

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布日期上次发布2015年5月

Daniel Bowden 维护。




一个 UITableViewCell 的子类,用于 iOS 7,帮助自动布局动态高度的表格视图。它使用了创建原型单元格,并使用 systemLayoutSizeFittingSize 将父视图调整为 UILayoutFittingCompressedSize 的方法来根据自动布局约束调整子视图的大小。而不是现在已弃用的旧方法(如 sizeWithFont 等)。

包含示例项目。克隆仓库,然后打开 "DBDynamicHeightTableCellDemo.xcworkspace"。

Orta TheroxCocoapodsPod5播客 - 第13集 中提到。

使用方法

创建一个类似于示例的 DBDynamicHeightTableCell 子类(InfoCell.h/m/xib)。

实现抽象方法 - (void)populateWithObject:(id)object;。这用于填充您的单元格视图。基本示例

- (void)populateWithObject:(id)object
{
    self.headlineLabel.text = [object headline];
    self.summaryLabel.text = [object summary];
}

Plain text labels

您甚至可以使用格式化的字符串,不同的字体大小、颜色等。

- (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;
}

Attributed text labels

要引用您的单元格 xib,实现抽象方法 + (UINib *)nib;

+ (UINib *)nib
{
    return [UINib nibWithNibName:@"InfoCell" bundle:nil];
}

Autolayout constraints

为您的单元格中的子视图设置自动布局约束,以使其知道如何增长/收缩。

安装

作者

Daniel Bowden

github.com/danielbowden

twitter.com/danielgbowden

许可证

DBDynamicHeightTableCell 可在 MIT 许可下使用。更多信息请查看 LICENSE 文件。