-(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