how to remove UITableView offset on the left in Swift
ios, swift, uitableview
Solution
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
if(self.respondsToSelector(Selector("setSeparatorInset:"))){
self.separatorInset = UIEdgeInsetsZero
}
// iOS 8
if(self.respondsToSelector(Selector("setLayoutMargins:"))){
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
if(cell.respondsToSelector(Selector("setLayoutMargins:"))){
cell.layoutMargins = UIEdgeInsetsZero;
}
Problem
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]; } ```