Reputation: 245
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];
}
Upvotes: 7
Views: 12719
Reputation: 11
You can do this via the console by modifying the "Default Insets" to be "Custom Insets"
Image showing default settings
Imgage showing custom settings
Upvotes: 1
Reputation: 438
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
Upvotes: 3
Reputation: 2227
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;
}
Upvotes: 9
Reputation: 196
You can just set the property: tableView.separatorInset = UIEdgeInsetsZero
Upvotes: 14