UILabel in UITableViewCell with auto layout has wrong height

前端 未结 6 946
孤独总比滥情好
孤独总比滥情好 2021-02-01 19:00

I have a UITableView with cells that have a fixed height of 100 points. The cells are created in a xib file that uses 3 constraints to pin a UILabel to

6条回答
  •  盖世英雄少女心
    2021-02-01 19:27

    Stupid bug! I've lost almost one day in this problem and finally I solved It with Steven Vandewghe's solution.

    Swift version:

    override func layoutSubviews() {
        super.layoutSubviews()
        self.contentView.layoutIfNeeded()
        self.myLabel.preferredMaxLayoutWidth = self.myLabel.frame.size.width
    }
    

提交回复
热议问题