I have a problem in my application design. I want to set vertical align middle of my UITextView. Please help me how to set vertical align of uitextview from interface builder.
Got this to work by observing changes to the contentSize property and then setting contentOffset.
- (void)viewDidLoad{
[super viewDidLoad];
[myTextView addObserver:self forKeyPath:@"contentSize" options:(NSKeyValueObservingOptionNew) context:nil];
}
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
UITextView *myView = object;
CGFloat offSet = ([myView bounds].size.height - [myView contentSize].height * [myView zoomScale])/2.0;
offSet = offSet < 0.0 ? 0.0 : offSet;
[myView setContentOffset:CGPointMake(0, -offSet) animated:NO];
}
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