How to remove UITableView offset left in Swift

I found several questions and answers to remove the offset of UITableViews in ios7, namely here How to fix the UITableView delimiter on iOS 7?

I was wondering if anyone came across the correct functions to remove input fields. Something similar to this answer in objective-c

if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) { [tableView setSeparatorInset:UIEdgeInsetsZero]; } 
+7
ios uitableview swift
source share
5 answers

Like the Objective-C example, but converted to fast. I had some problems. This code works in a UITableView, if you do this in a UITableViewController, you replace self.tableView for yourself:

 // 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), enter 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; } 
+9
source share

You can simply set the property: tableView.separatorInset = UIEdgeInsetsZero

+12
source share

Put the following lines in viewDidLoad()

 tableView.layoutMargins = UIEdgeInsetsZero tableView.separatorInset = UIEdgeInsetsZero 

Now find your cellForRowAtIndexPath method and add the following:

 cell.layoutMargins = UIEdgeInsetsZero 

currently the syntax is ".zero" ...

  tableView.layoutMargins = UIEdgeInsets.zero tableView.separatorInset = UIEdgeInsets.zero cell.layoutMargins = UIEdgeInsets.zero 
+3
source share

for Swift 3 just type:

 tableView.separatorInset = .zero 
+1
source share

You can do this through the console by changing "Default Inserts" to "Custom Inserts"

  • Inside the table view cell, click the slider icon
  • In the Table View Cell section, go to the "Default Partition" section.
  • Click the drop-down menu and select Custom Inserts
  • Select your left and right number (I have set my value 0 for the edge-to-edge delimiter)

Image showing default settings

User Preferences Identification

0
source share

All Articles