I have a question about UITableView... I have a UITableViewController and I created a custom cell. When I visualize the tableView I see a little white space before the separator line as you can see into this screenshot:
Why? It is a default visualize? Can I change something to remove this white left padding?
There is no white space! I entered a bug on this, Apple just closed it as "not a bug", but told me why its not a bug. I wrote a simple project that sets a color for every possible view in the app. What I see is that the color of those pixels is actually the background color of the cell itself (not the contentsView!), just as Apple had told me.
The cell.contentView.backgroundColor is green, and the cell.background color is red (taken with Pixie):
In the end, without a separator, the cell.contentView fills the cell completely. With a separator, there is a pixel or two gap at the bottom. The separator, when inset, fills the most of the gap, but there are then some pixels of the cell showing through.
Mystery solved!
EDIT: It seems that depending on how you configure your Storyboard, that the contentView.backgroundColor gets "lost" or set to White. If you over ride it when supplying cells you can get the behavior your want:
The leading whitespace is provided by default in iOS 7, even for custom cells.
Checkout this property
separatorInset
of UITableviewCell to remove/add white spacing at either ends of cell's line separator.// Remove white space
Alternatively, at UITableView level, you can use this property -
Update - Below code works on iOS 7 and iOS 8:
Alternatively, you can also edit this in interface builder (IB):
This has the same effect as @Ashok's answer, but doesn't require writing any code.
Update Works on iOS 7 and 8
Update Works on iOS 9
For those of you who want to make the retain the UIEdgeInsetSettings in Swift and are not using Storyboards:
Before: (Default Behavior)
Add the following code:
Swift
This one worked for me
Thanks
Here is an extension to UITableViewCell Class for swift 3 & later
Usage:
Hope this helps some one!
Naresh.