Closed pranavss11 closed 8 years ago
register the observer on [textView valueForKey:@"_placeholderTextView"]
and not the SZTextView instance itself?
[[self.textView valueForKey:@"_placeholderTextView"] addObserver:self forKeyPath:@"contentSize" options:(NSKeyValueObservingOptionNew) context:NULL];
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
UITextView *tv = object;
CGFloat topCorrect = ([tv bounds].size.height - [tv contentSize].height * [tv zoomScale])/2.0;
topCorrect = ( topCorrect < 0.0 ? 0.0 : topCorrect );
tv.contentOffset = (CGPoint){.x = 0, .y = -topCorrect};
}
Still doesn't work. Strange. Text is still aligned to at top.
I am trying to center my text vertically using:
http://stackoverflow.com/questions/12591192/center-text-vertically-in-a-uitextview
but it seems like it doesn't work. Any idea how I can accomplish this?