swift 自动布局设置 tableview 的 tableHeaderView 的高度


class headerView: UIView {
    
    var whiteView = UIView().then {
        $0.backgroundColor = UIColor.red
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        addSubview(whiteView)
        whiteView.snp.makeConstraints { (make) in
            make.left.top.right.equalToSuperview()
            make.bottom.equalTo(-20)
            make.height.equalTo(200)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
    }
}

 

设置 tableHeaderView 的高度

        let v = headerView()
        let height = CGFloat(v.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).height)
        v.frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: height)
        tabelView.tableHeaderView = v

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM