In my tableView cell, I have a textView whose string i'm getting via JSON and updating the cell height dynamically like this
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.section == 0 {
return 255
}
return UITableViewAutomaticDimension
}
Here's a screenshot
Now initially i want text view to show a little text and upon clicking see more button it should expand and upon expansion the button text should change to see less also if the string's length is just a couple of lines, the see more button should hide. The solution's i've came across involve UILabel
and i can't use it because then the cell's height won't become dynamic. Also there's no property of textView like numberOfLines
so i can work with it. Please point me in a right direction what should i do.
Use this extension like the below code,
Please try using the above extension method where you pass in the width of your textview and the font. This method will dynamically set the height of your textview. Also put your own logic for calculating what will happen on see more and see less buttons.