That would be a bit complicated. You will need to observe contentSizeyour property UITextView, and then adjust it contentSizeand contentOffsetas follows:
- (void) viewDidLoad {
[self.textView addObserver:self forKeyPath:@"contentSize" options:(NSKeyValueObservingOptionNew) context:NULL];
[super viewDidLoad];
}
- (void)observeValueForKeyPath:(NSString *)iKeyPath ofObject:(id)iObject change:(NSDictionary *)iChange context:(void *)iContext {
UITextView *myTextView = (UITextView *)iObject;
CGFloat topCorrect = (myTextView.bounds.size.height - [myTextView contentSize].height * [myTextView zoomScale]) / 2.0;
topCorrect = (topCorrect < 0.0 ? 0.0 : topCorrect);
myTextView.contentOffset = (CGPoint){.x = 0, .y = -topCorrect};
}
source
share