I'm attempting to vertically align a UITextView by setting the content offset appropriately.
I'm calling the following code when I change the text of my textView:
- (void)setCenterVerticalAlignmentForTextView:(UITextView*)textView {
CGFloat topCorrect = ([textView bounds].size.height - [textView contentSize].height * [textView zoomScale])/2.0;
topCorrect = (topCorrect < 0.0 ? 0.0 : topCorrect );
textView.contentOffset = CGPointMake(0,-topCorrect);
}
This works perfectly the first time the UIView is shown on the screen.
However, if I change the text inside the textView and call this function again, the last line of the function which sets the contentOffset doesn't seem to make any difference. The content offset becomes (0,0) no matter what I set.
Do I need to do something to reset the contentOffset or contentInset before I attempt to reset it?
Thanks guys, any help much appreciated.
Duncs