Reputation: 283
I used this codes in my app to align my textView
vertically center and it was working until iOS 7.1
.
I guess contentSize
property is changed in iOS 7.1
how can you help me with that?
[textView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil];
- (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 : topCorrect);
tv.contentOffset = (CGPoint) {.x = tv.contentOffset.x, .y = - topCorrect};
}
Upvotes: 2
Views: 1496
Reputation: 3672
I had the same problem and what worked for me was using
[tv sizeThatFits:tv.bounds.size].height
instead of tv.contentSize.height
Upvotes: 3