码迷,mamicode.com
首页 > 其他好文 > 详细

UITextview 垂直居中

时间:2015-08-31 23:02:46      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:


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

    

} 

UITextview 垂直居中

标签:

原文地址:http://www.cnblogs.com/li-baibo/p/4774230.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!