Created
February 10, 2016 16:37
-
-
Save mteece/a5e95afcd2672be20775 to your computer and use it in GitHub Desktop.
Fix for heightForHeaderInSection as it is called before viewForHeaderInSection and the view size until I create it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (CGSize)tableView:(UITableView *)tableView sizeForHeaderLabelInSection:(NSInteger)section | |
{ | |
NSString *text = [self tableView:tableView titleForHeaderInSection:section]; | |
CGSize constraint = CGSizeMake(self.view.frame.size.width - kSectionTitleLeftMargin - kSectionTitleRightMargin, kMaxSectionTitleHeight); | |
return [text sizeWithFont:[self fontForSectionHeader] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap]; | |
} | |
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section | |
{ | |
return [self tableView:tableView sizeForHeaderLabelInSection:section].height + kSectionTitleTopMargin + kSectionTitleBottomMargin; | |
} | |
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section | |
{ | |
CGSize size = [self tableView:tableView sizeForHeaderLabelInSection:section]; | |
UIView* headerView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, size.width + kSectionTitleLeftMargin + kSectionTitleRightMargin, size.height + kSectionTitleTopMargin + kSectionTitleBottomMargin)]; | |
//headerView.contentMode = UIViewContentModeScaleToFill; | |
// Add the label | |
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(kSectionTitleLeftMargin, | |
kSectionTitleTopMargin, | |
size.width, | |
size.height)]; | |
// put stuff to set up my headerLabel here... | |
[headerView addSubview:headerLabel]; | |
// Return the headerView | |
return headerView; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment