Automatically increase/decrease UILabelView Height in UITableViewCell?

后端 未结 2 674
挽巷
挽巷 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:38
    1. Set tableView.rowHeight = UITableViewAutomaticDimension
    2. Remove this function in your code func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
    3. Set height constraint of LabelBio greaterOrEqualThan 0
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题