I'm trying to set left border to each table view cell programmatically. I'm using UIView as a border but I cannot display the UIView for some reason. Also how should I set the UIView height? Thank you.
class Cell: UITableViewCell {
var borderLeft: UIView = {
let view = UIView()
view.frame.size.width = 3
view.frame.size.height = 20
view.backgroundColor = .red
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.backgroundColor = .black
addSubview(borderLeft)
borderLeft.topAnchor.constraint(equalTo: self.topAnchor, constant: 0).isActive = true
borderLeft.leftAnchor.constraint(equalTo: self.leftAnchor, constant: 0).isActive = true
borderLeft.rightAnchor.constraint(equalTo: self.rightAnchor, constant: 0).isActive = true
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
contentView
or under thebackgroundView
. You should add all custom views to one of them.