By default there is a single line separator in uitableview.
But I want to put my customized line as a separator.
Is it possible? How?
If you are using Custom Cells in Swift: An alternative approach is to extend UITableViewCell with a function that can draw a line at the top of that cell.
import UIKit
extension UITableViewCell {
func addSeparatorLineToTop(){
let lineFrame = CGRectMake(0, 0, bounds.size.width, 1)
let line = UIView(frame: lineFrame)
line.backgroundColor = UIColor.myGray_300()
addSubview(line)
}
}
Then you can add this line to any custom cell, for example in the awakeFromNib
override func awakeFromNib() {
super.awakeFromNib()
addSeparatorLineToTop()
}
This solution is nice because it does not mess up your storyboard and limits your extra code to 1 line.