I'm using the following code to have the UITableViewCell have a dynamic height:
tableView.estimatedRowHeight = 155
tableView.rowHeight = UITableViewAutomaticDimension
And this code to have the UITextView change it's height based on the content.
extension NewUserTweetTableVC: UITextViewDelegate {
func textViewDidChange(textView: UITextView) {
let fixedWidth = textView.frame.size.width
textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.max))
let newSize = textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.max))
var newFrame = textView.frame
newFrame.size = CGSize(width: max(newSize.width, fixedWidth), height: newSize.height)
textView.frame = newFrame
}
}
Once I change the text of the UITextView during runtime, the height of the UITextView changes, but the height of the UITableViewCell does not. How can I change that? Help is very appreciated.
Get programmatically height of textview...
let textView = UITextView()//your Text view
let sizeThatShouldFitTheContent = textView.sizeThatFits(textView.frame.size)
let height = sizeThatShouldFitTheContent.height
OR try this demo...
Self-sizing UITextView in a UITableView
https://www.damienpontifex.com/posts/self-sizing-uitableviewcell-with-uitextview-in-ios8/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With