How to change separator height in UITableView Swift 3?

前端 未结 4 1376
抹茶落季
抹茶落季 2021-01-07 05:59

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 heig

4条回答
  •  旧时难觅i
    2021-01-07 06:56

    For Those who want to do it using autolayout here is the code

    var additionalSeparator:UIView = UIView()
    override func awakeFromNib() {
            super.awakeFromNib()
            self.createSeparator()
        }
        func createSeparator() {
    
            self.additionalSeparator.translatesAutoresizingMaskIntoConstraints = false
            self.contentView.addSubview(self.additionalSeparator)
        }
        func setConstraintForSeparator() {
            self.additionalSeparator.leadingAnchor.constraint(equalTo: self.contentView.leadingAnchor, constant: self.separatorInset.left).isActive = true
            self.additionalSeparator.trailingAnchor.constraint(equalTo: self.contentView.trailingAnchor, constant: -self.separatorInset.right).isActive = true
            self.additionalSeparator.bottomAnchor.constraint(equalTo: self.contentView.bottomAnchor, constant: 0).isActive = true
            self.additionalSeparator.heightAnchor.constraint(equalToConstant: 1).isActive = true
            self.additionalSeparator.backgroundColor = UIColor.greyishBrown
        }
    

提交回复
热议问题