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.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With