小编Fra*_*sco的帖子

在iOS 9中的UItextView中垂直居中文本

自iOS 9更新以来,以下代码对我来说不再适用.

-(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 ? 0.0 : topCorrect );
    tv.contentOffset = (CGPoint){.x = 0, .y = -topCorrect};
}

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:NO];
    [questionTextView addObserver:self forKeyPath:@"contentSize"    options:(NSKeyValueObservingOptionNew) context:NULL];

}
Run Code Online (Sandbox Code Playgroud)

对于iOS 9,是否有垂直居中文本的解决方法?

objective-c uitextview

3
推荐指数
1
解决办法
1761
查看次数

标签 统计

objective-c ×1

uitextview ×1