Search code examples
iosobjective-cuitableviewios7padding

TableView ContentInset does not shrink cell width / Add horizontal padding to TableView contents


I'd like to have a UITableView which is full screen. But the content of the UITableView should have a padding on the left and right.

So I tried to set ContentInset. But now the cells are as wide as the UITableView and the UITableView scrolls horizontally.

Is there a way to say that the UITableView content's width should become narrowed by the horizontal content insets? Or do I have to add the padding to all cells and header/footer views?

I don't want to narrow the table view itself, because the scroll indicator should stay at the right side of the screen and not in the middle. The here (How to set the width of a cell in a UITableView in grouped style) suggested solution seems to be not as generic as i'd love to, beacuse the cells and header and footer views have to know about the padding (at least 3 places to maintain instead of one)


Solution

  • I don't want to narrow the table view itself, because the scroll indicator should stay at the right side of the screen and not in the middle.

    This makes you happy?

    _tableView.clipsToBounds = NO;
    _tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 0, -30.f);
    

    If you don't like clipsToBounds = NO effects, you can embed the tableView in container view which is clipsToBounds = YES.