Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Height of UITableViewHeaderFooterView

How can I calculate the height of a UITableViewHeaderFooterView in -tableview:heightForFooterInSection:? I create the view ahead of time, and it contains dynamic text in the textLabel so has a varying height.

like image 482
Nick Avatar asked Dec 31 '25 23:12

Nick


1 Answers

Based on the other answers I used the following, I'm not entirely happy with this solution as it uses a hardcoded padding and it doesn't account for the detailTextLabel, but it works in my case.

- (CGFloat)heightOfHeaderFooterView:(UITableViewHeaderFooterView *)view {
    return ceilf([view.textLabel.text boundingRectWithSize:CGSizeMake(self.tableView.bounds.size.width - 2*self.tableView.separatorInset.left, CGFLOAT_MAX) options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) attributes:@{NSFontAttributeName:view.textLabel.font} context:nil].size.height) + 20;
}
like image 144
Nick Avatar answered Jan 02 '26 15:01

Nick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!