Change cell height by the content of the textView inside the cell

后端 未结 3 698
醉梦人生
醉梦人生 2020-12-11 04:11

I have a Table View called todoTableView with cells that created by the user. Each cell has Text View. I want to change the height of the cell by the content of

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-11 04:48

    Bound Your textview with cell from all sides using marginal constraints.(Leading, Trailing, Top and Bottom constraints)

    • Disable textView Scrolling

    In viewDidLoad() add the following.

    tableView.estimatedRowHeight = 44.0
    tableView.rowHeight = UITableViewAutomaticDimension
    

    This will make your cell size according to your textview content size.

    Have a look at result :

    You don't need to write heightForRowAtIndexPath.

提交回复
热议问题