How to change separator height in UITableView Swift 3?

Although there are several answers already on this topic. None of them covers Swift 3, and they have long been. What is the best way to change the height of a separator in a UITableView in Swift 3?

0
ios uitableview swift swift3
Jun 23 '17 at 1:16
source share
2 answers

Updated for Swift 3:

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

 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) } 
+2
Aug 26 '17 at 7:48 on
source share

Try this Swift 3:

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: YOUR_CELL_IDENTIFIER, for: indexPath) as! yourTableViewCell let viewSeparatorLine = UIView(frame:CGRect(x: 0, y: cell.contentView.frame.size.height - 5.0, width: cell.contentView.frame.size.width, height: 5)) viewSeparatorLine.backgroundColor = .red cell.contentView.addSubview(viewSeparatorLine) return cell } 
-2
Jun 23 '17 at 1:47 on
source share



All Articles