21

问候!我知道UITableView sectionHeaderHeight仅用于分组表,但无论如何我都会问(以防有一些不明显的方法来做到这一点)......

有没有办法更改NON分组表的节标题高度(以及字体/大小)?

希望“是”或至少是“也许”......但担心它可能是“不”。加油吧,伙计们。

4

2 回答 2

49

Yes.

Use this delegate method:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 44;
}

Of course, change as appropriate. There's of course the one for footer as well:

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 44;
}
于 2009-09-28T22:56:49.277 回答
1

至少从 iOS 9(经过测试)开始UITableView.sectionHeaderHeight也适用于普通表视图(非分组)!

您将获得默认标题高度(通常为 22.0)。

当然,表视图委托可能已经在其tableView:heightForHeaderInSection:方法中自定义了这个默认值。

以下代码片段给出了定义的节标题的高度:

CGFloat headerHeight = self.tableView.sectionHeaderHeight;
if ([self.tableView.delegate respondsToSelector:@selector(tableView:heightForHeaderInSection:)]) {
    // possibly custom header height
    headerHeight = [self.tableView.delegate tableView:self.tableView heightForHeaderInSection:indexPathForCell.section];
}
于 2016-02-15T18:13:02.830 回答