-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
NSLog(@"Hello");
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};
}
我打電話像這樣在viewDidLoad中的TextView中心文本對齊IOS 7
[myTextView1 addObserver:self forKeyPath:@"contentSize" options:(NSKeyValueObservingOptionNew) context:NULL];
這是垂直對齊?是否有任何理由通過UILabel使用UITextView?該標籤將爲您免費提供此功能。 – SomeGuy
http://stackoverflow.com/questions/17024375/uitextview-alligining-text-vertically-center?rq=1 – peko