How to change separator height in UITableView Swift 3?

前端 未结 4 1293
抹茶落季
抹茶落季 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条回答
  •  心在旅途
    2021-01-07 06:47

    Updated for Swift 3:

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

    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)
    }
    

提交回复
热议问题