UITableView section header inset missing
Asked Answered
A

2

11

How do I fix the problem illustrated in the image?

The section header for the tableview is missing an inset.

section header for the tableview is missing an inset.

Anorthite answered 19/12, 2014 at 7:54 Comment(2)
Have you tried going to the Size Inspector and changing the height of the header?Nerynesbit
No, tried it but it didn't help. Thanks though!Anorthite
H
20

You probably set the separator insets to 0, either in code or in the Interface Builder (can be found in the Attributes inspector:

Separator insets set to 0

This also causes the titles to have no inset. The default values are 15 for left and 0 for right.

Hajji answered 19/12, 2014 at 9:13 Comment(1)
thanks! I wasn't doing that in IB, but i was calling """if ([self.tableView respondsToSelector:@selector(separatorInset)]) { [self.tableView setSeparatorInset:UIEdgeInsetsZero]; }"""Anorthite
O
5

[Could you post your code of UITableViewDelegate? In UITableView, there is no API for you to set this insets in section header, so you could return a custom UIView in tableView:viewForHeaderInSection: then set the layout you want.

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *headerView = [UIView alloc] init];
    UILabel *headerLabel = [UILabel alloc] init];
    headerLabel.text = @"xxx";
    [headerLabel sizeToFit];
    headerLabel.frame = CGRectMake(20, 0, CGRectGetWidth(headerLabel.frame), CGRectGetHeight(headerLabel.frame));
    [headerView addSubview:headerLabel];
    headerView.frame = CGRectMake(0, 0, CGRectGetWidth(tableView.bounds), CGRectGetHeight(headerLabel.frame));
    return headerView;
}
Oyler answered 19/12, 2014 at 9:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.