johnnywu johnnywu - 1 year ago 123
Swift Question

how to remove UITableView offset on the left in Swift

I've found some questions and answers to remove offset of UITableViews in ios7, namely this one here
How to fix UITableView separator on iOS 7?

I was wondering if anyone had come across the correct functions to remove inset margins. Something similar to this answer in objective-c

if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[tableView setSeparatorInset:UIEdgeInsetsZero];

Answer Source

Just like the Objective-C example, but converted to swift. I had some trouble myself. This code works in a UITableView if you were doing it in a UITableViewController you would substitute self.tableView for self:

// iOS 7
    self.separatorInset = UIEdgeInsetsZero

// iOS 8
    self.layoutMargins = UIEdgeInsetsZero;

And for the cell (iOS 8 only) put the code below in the following function:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)

get the cell, and set the following property:

// iOS 8
    cell.layoutMargins = UIEdgeInsetsZero;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download