UITextview 垂直居中


 UITextView* content = (UITextView*) [cell viewWithTag:104];

[content addObserver:self forKeyPath:@"contentSize" options:(NSKeyValueObservingOptionNew) context:NULL];

#pragma mark - KVO

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context

{

    UITextView *tv = object;

    // Center vertical alignment

    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};

    

} 

posted @ 2015-08-31 21:52  李伯波  阅读(960)  评论(0编辑  收藏  举报