Automatically increase/decrease UILabelView Height in UITableViewCell?

后端 未结 2 699
挽巷
挽巷 2021-01-27 17:53

Hello I have a UITableView with x# of cells. the last cell I have two UILabels. When the second UILabel text is set I am trying to get the cell and the UILabel to resize to sh

2条回答
  •  日久生厌
    2021-01-27 18:44

    here are the steps ...

    • hope you know about autylayout. use constraints (left to content view, right to content view, bottom to content view and verticle to your first label)

    • then in your viewdidLoad method add YourTableView.estimatedRowHeight = 200 -> give any height you want.

    • finally define below method :

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
            return UITableViewAutomaticDimension
        }
    

    you good to go.

提交回复
热议问题