How do I adjust the left margin for prototype cells in a UITableView?
Starting from iOS 8 is available the cell property layoutMargins
.
So the correct way to adjust cell margins is setting this property in your tableView:cellForRowAtIndexPath
or in your custom UITableViewCell
in this way:
override func awakeFromNib() {
super.awakeFromNib()
self.layoutMargins = UIEdgeInsetsZero //or UIEdgeInsetsMake(top, left, bottom, right)
self.separatorInset = UIEdgeInsetsZero //if you also want to adjust separatorInset
}
I hope this can help someone.
Go to Main.storyboard
> select the UITableViewCell
> Attributes Inspector
. Change Separator dropdown list from Default Insets to Custom Insets. Change the left inset from 15 to 0
You just need to set contentInset
property of the table view. You can set value according to your need.
self.tableView.contentInset = UIEdgeInsetsMake(0, -15, 0, 0);
OUTPUT RESULT