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];
}
You can just set the property: tableView.separatorInset = UIEdgeInsetsZero
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;
}
Put the following lines in viewDidLoad()
tableView.layoutMargins = UIEdgeInsetsZero
tableView.separatorInset = UIEdgeInsetsZero
Now look for your cellForRowAtIndexPath
method and add this:
cell.layoutMargins = UIEdgeInsetsZero
nowadays ".zero" syntax...
tableView.layoutMargins = UIEdgeInsets.zero
tableView.separatorInset = UIEdgeInsets.zero
cell.layoutMargins = UIEdgeInsets.zero
for Swift 3 just type:
tableView.separatorInset = .zero
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With