I have looked everywhere. Trying to increase the thickness of this line. Is there anyway to do this programmatically? Thanks
My solution to this was to add an extension to either UIView or a UITableViewCell.
extension UIView {
func addSeparator(ofHeight height : CGFloat) {
let lineView = UIView()
lineView.backgroundColor = .red
self.addSubview(lineView)
let constraintString = "V:|-\(self.frame.size.height - height)-[v0(\(height))]|"
self.addConstraintsWithFormat("H:|[v0]|", views: lineView)
self.addConstraintsWithFormat(constraintString, views: lineView)
}
//MARK: - Constraints Extension
func addConstraintsWithFormat(_ format: String, views: UIView...) {
var viewsDictionary = [String: UIView]()
for (index, view) in views.enumerated() {
let key = "v\(index)"
view.translatesAutoresizingMaskIntoConstraints = false
viewsDictionary[key] = view
}
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: format, options: NSLayoutFormatOptions(), metrics: nil, views: viewsDictionary))
} }
Then use it within your custom TableViewCell or any View you would like to add a bottom line to.
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
self.addSeparator(ofHeight: 1)
}
The only way of doing it, is setting the separtorStype to UITableViewCellSeparatorStyleNone and then you have two options:
private let kSeparatorId = 123
private let kSeparatorHeight: CGFloat = 1.5
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath)
{
if cell.viewWithTag(kSeparatorId) == nil //add separator only once
{
let separatorView = UIView(frame: CGRectMake(0, cell.frame.height - kSeparatorHeight, cell.frame.width, kSeparatorHeight))
separatorView.tag = kSeparatorId
separatorView.backgroundColor = UIColor.redColor()
separatorView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
cell.addSubview(separatorView)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With