Dynamically increase height of UILabel & TableView Cell?

前端 未结 7 1739
广开言路
广开言路 2020-12-01 12:52

I have a UITableView in which i am displaying a custom cell.I my cell i have two label & one view as below in picture.

I have given constraint of left v

7条回答
  •  清歌不尽
    2020-12-01 13:17

    This is how I worked out.

    1) Set no. of lines to 0.

    2) Set LineBreakage.

    3) Add Constraints.

    4) Change vertical content hugging priority.

    5) On ViewDidLoad:

    override func viewDidLoad() {
        super.viewDidLoad()
    
        self.sampleTableView.estimatedRowHeight = 600.0;
        self.sampleTableView.rowHeight = UITableViewAutomaticDimension;
    
        self.sampleTableView.setNeedsLayout()
        self.sampleTableView.layoutIfNeeded()
    }
    

    6) On TableView Custom Cell:

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    
        sizeToFit()
        layoutIfNeeded()
    }
    

提交回复
热议问题