separatorInset and layoutMargins to .zero, and set preservesSuperviewLayoutMargins to false. Apply these values in tableView(_:willDisplay:forRowAt:) so they are configured when the cell is displayed.Why this happens
A zero separatorInset does not necessarily make a UITableViewCell separator reach the edge of the table. UIKit also uses layout margins, and a cell can preserve margins inherited from its superview. As a result, a separator can still appear indented even when its inset is zero in a storyboard or XIB.
This behavior became especially noticeable when iOS 8 introduced layout margins for table views and cells. On newer systems, safe-area behavior can also affect effective margins. The fix is to configure the cell’s inset and margins together, rather than changing only the table view’s separator inset.
How to fix it
1. Configure each cell before display
Use the table view delegate’s willDisplay method to set the separator inset and layout margins on the actual cell being shown. Disable superview margin preservation so the cell does not have to inherit larger margins from its container.
In a UITableViewController, the implementation can look like this:
import UIKit
final class ItemsViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
tableView.separatorInset = .zero
}
override func tableView(
_ tableView: UITableView,
willDisplay cell: UITableViewCell,
forRowAt indexPath: IndexPath
) {
cell.separatorInset = .zero
cell.preservesSuperviewLayoutMargins = false
cell.layoutMargins = .zero
}
}
The table-level setting provides a consistent starting point. The three cell-level assignments address the separator inset, inherited margins, and the cell’s own margins respectively.
If your table is managed by a regular UIViewController instead, implement the same delegate method without override and ensure that the controller is the table view’s delegate. Do not create a second delegate solely for this fix: a table view has one delegate, so add the method to the object already handling its delegate callbacks.
Run the app and inspect rows that initially appear as well as rows revealed by scrolling. willDisplay runs when a cell is about to appear, making it a useful place to apply the settings consistently as cells are reused.
2. Check settings on the cell, not just the table
If the separator is still indented, look for code or interface-file settings that configure the cell separately from the table.
- Check the prototype cell or XIB used by the affected row. A table-level change does not replace the need to check the cell’s own inset.
- Search your cell subclass and table view delegate for assignments to
separatorInset,layoutMargins, andpreservesSuperviewLayoutMargins. - If different rows use different cell subclasses, confirm that each affected cell reaches the
willDisplayimplementation. - Check for later configuration that changes the values again, especially when a reusable cell is prepared for another row.
You can set the same properties during cell configuration instead of in willDisplay. The important part is to apply them to every relevant cell and avoid conflicting assignments elsewhere. willDisplay is convenient when you want one policy for all rows in a table.
Setting a margin to zero does not remove the separator itself. If there is no line at all, check the table view’s separatorStyle and any custom drawing or views covering the separator before troubleshooting its inset.
3. Consider safe-area margins when you need full-bleed lines
On iOS 11 and later, a view’s margins can be adjusted for the safe area. That can be desirable: an inset helps keep content clear of screen edges and other system-obstructed areas. If your design specifically requires edge-to-edge separators, review that behavior rather than assuming a zero assignment always means a zero effective margin.
For example, you can opt the cell out of safe-area margin adjustment in the display callback:
if #available(iOS 11.0, *) {
cell.insetsLayoutMarginsFromSafeArea = false
}
Add this alongside the cell settings in step 1, not as a replacement for them. Test the result in the device orientations and table layouts your app supports. This setting affects the cell’s layout margins, so it can also affect content that uses those margins; it is not a separator-only switch.
If an inset remains, inspect the surrounding table layout and any custom cell constraints as well. Changing safe-area behavior on the cell alone does not guarantee a full-width line in every layout.
4. Use a cell subclass override only when necessary
A custom cell can override layoutMargins to always report zero:
import UIKit
final class ZeroMarginCell: UITableViewCell {
override var layoutMargins: UIEdgeInsets {
get { .zero }
set { }
}
}
Assign this class to the relevant cell and continue to configure its separatorInset as needed. The empty setter deliberately ignores attempts to change the margins.
This is a blunt alternative, not the first choice. It prevents normal margin changes from taking effect through that property and can interfere with system behavior, including safe-area-related margins. Prefer the explicit assignments in willDisplay when you need conditional behavior or want the cell to retain normal margin handling elsewhere.
As a last diagnostic step, you can also set the table view’s layoutMargins and separatorInset to .zero in viewDidLayoutSubviews. That callback can run repeatedly, and changing the table’s margins may affect more than separators, so keep the change only if you have confirmed it is needed for your layout.
How to prevent it
- Decide whether separator alignment should follow readable content margins or reach the table’s edges.
- Configure the cell’s inset and margins together when using a full-width separator design.
- Keep margin assignments in one predictable place so reuse and later configuration do not undo them.
- Check safe-area and content alignment in the orientations your app supports.
- Avoid overriding
layoutMarginsglobally just to fix one table.
FAQ
Why doesn’t a zero table view separator inset fix every row?
Cells have their own separator insets and layout margins. A cell can also preserve margins from its superview, so configure the displayed cells as well as the table when you need a consistent result.
Does setting layoutMargins to zero remove the separator?
No. It changes margins used in layout; it does not disable the line. Use the table view’s separator settings if your goal is to hide separators rather than change their alignment.
Do I need availability checks for the iOS 8 margin properties?
Only code that still supports systems earlier than iOS 8 needs to guard those property assignments. The safe-area property shown above was introduced later, so use an availability check if your deployment target includes versions before iOS 11.
Parts of this guide are adapted from content licensed under CC BY-SA 3.0; this article is shared under the same license.