UITableViewCell Separator. Hide Separator or Change Left Side Spacing

In this video tutorial I am going to share with you how to change UITableViewCell separator left side spacing or how to hide table cell separator completely using Xcode and how to do it programmatically using Swift.

If you are looking for a way to work with table cell separator programmatically only, below is a quick example. Otherwise, please watch the video.

 Remove UITableViewCell Separator left side space programmatically

  1. Implement cellForRowAtIndexPath function of your UITableViewDataSource
  2. Just before returning the value of UITableViewCell, add the two lines which are marked in bold below
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
   {
let myCell = tableView.dequeueReusableCellWithIdentifier("myCell", forIndexPath: indexPath) 
as! MyCustomTableViewCell

...

myCell.layoutMargins = UIEdgeInsetsZero
myCell.separatorInset = UIEdgeInsetsZero

return myCell
}

Hide UITableViewCell Separator

To hide UITableViewCell separator completely, simply set it’s colour to UIColor.clearColor(). This will make the cell separator not visible.

@IBOutlet weak var myTableView: UITableView!
...
override func viewDidLoad() {
 super.viewDidLoad()
 self.myTableView.separatorColor = UIColor.clearColor()
}

Watch this video for a complete example and please do subscribe if you are interested in more weekly video tutorials like this.

 

Below are my other tutorials that have to do with UITableViewCell or UITableView

Swift UITableViewController + custom UITableViewCell

UITableViewController rearrange or reorder table cells example in Swift

UITableViewController delete table cell example in Swift

I hope this very short video tutorial is of some value to you! 🙂

Happy coding!