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

计算UITextView的滑动高度

时间:2015-03-20 21:39:37      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:

 1 - (CGFloat)getHeightByTextView:(UITextView *)myTextView withContent:(NSString *)content withFontSize:(CGFloat)size withTextColor:(UIColor *)color
 2 {
 3     CGFloat newSizeH = 0.;
 4     //UITextView的实际高度
 5     if ([[[UIDevice currentDevice] systemVersion] floatValue]>=7.0)
 6     {
 7         //7.0以后需要自己计算高度
 8         float fPadding = 16.0; //8.0px x 2
 9         
10 //        CGSize constraint = CGSizeMake(myTextView.contentSize.width - fPadding,CGFLOAT_MAX);
11 //        CGSize size = [self.textView.text sizeWithFont:myTextView.font constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping];
12 //        newSizeH = size.height;
13         
14         CGSize constraint = CGSizeMake(myTextView.contentSize.width - fPadding, CGFLOAT_MAX);
15         NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Helvetica Neue" size:size],NSFontAttributeName,color,NSForegroundColorAttributeName, nil];
16         NSStringDrawingOptions options = NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
17         CGRect rect = [myTextView.text boundingRectWithSize:constraint options:options  attributes:attrsDictionary context:nil];
18         newSizeH = rect.size.height;
19     }
20     else
21     {
22         newSizeH = myTextView.contentSize.height + 10;
23     }
24     return newSizeH;
25 }

 

计算UITextView的滑动高度

标签:

原文地址:http://www.cnblogs.com/farer-zcz/p/4354472.html

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