How to change separator height in UITableView Swift 3?

KevinZ picture KevinZ · Jun 23, 2017 · Viewed 13.3k times · Source

Although there a few answers already on this topic. None of them cover Swift 3 and they are from a long time ago. What is currently the best way to change the separator height in a UITableView in Swift 3?

Answer

Kiran Jadhav picture Kiran Jadhav · Aug 26, 2017

Updated for Swift 3:

If you want to change the height of the UITableView separator, use the code below.
You should add it to the UITableViewCell method awakeFromNib() to avoid re-creation.

override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code

    let mScreenSize = UIScreen.main.bounds
    let mSeparatorHeight = CGFloat(3.0) // Change height of speatator as you want
    let mAddSeparator = UIView.init(frame: CGRect(x: 0, y: self.frame.size.height - mSeparatorHeight, width: mScreenSize.width, height: mSeparatorHeight))
    mAddSeparator.backgroundColor = UIColor.brown // Change backgroundColor of separator
    self.addSubview(mAddSeparator)
}