Thursday, May 19, 2016

Horizontal Adjustment for Table Separator Lines

This example uses Xcode 7.3.1 (Swift 2.2) and iOS 9.3 simulator.

The default separator line in a tableView is like this:


Gaps exist at the left of the separator lines, white the right side of the horizontal lines touch the screen edge.

To eliminate the gaps at the left, add these lines:


tableView.separatorInset = UIEdgeInsetsZero

tableView.layoutMargins = UIEdgeInsetsZero

and this:


cell.layoutMargins = UIEdgeInsetsZero

Result:




To add gaps to the right of separators, simply add this line:


tableView.separatorInset.right = tableView.separatorInset.left

Result:



The separator lines are now centered.

Related Information:

White space before separator line into my TableView

iOS 8 UITableView separator inset 0 not working

Draw UITableView programmatically (without using the Storyboard)

No comments:

Post a Comment