-(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 中这样称呼它
[myTextView1 addObserver:self forKeyPath:@"contentSize" options:(NSKeyValueObservingOptionNew) context:NULL];
最佳答案
textView.textAlignment = NSTextAlignmentCenter;
关于iphone - Textview 中心文本对齐 IOS 7,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19219190/