Currently I can successfully resize my UITextView according to the amount of text within it.
My problem is that this UITextView is within a UITableViewCell. What I've tried to do is use the height of the resized UITextView to resize the cell by accessing it's frame and setting the height of that.
This is my code:
//dynamically resize textview and cell based on content
self.aboutMeTextView.text = profile["aboutMe"] as String
self.aboutMeTextView.sizeToFit()
self.aboutMeTextView.layoutIfNeeded()
var frame = self.aboutMeTextView.frame as CGRect
frame.size.height = self.aboutMeTextView.contentSize.height
self.aboutMeTextView.frame = frame
var cellFrame = self.aboutMeCell.frame as CGRect
cellFrame.size.height = self.aboutMeTextView.contentSize.height * 2
self.aboutMeCell.frame = cellFrame
It just doesn't work properly. The textView resizes but the cell doesn't resize properly and also my scrollView won't even scroll down enough for me to see the whole of the resized textview. I'm guessing if I can successfully set the cells height, the scrollView height will automatically adjust.
I've looked at similar questions but they haven't helped me.
Would appreciate some help.
Thanks for your time
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…