zoukankan      html  css  js  c++  java
  • 计算UITextView的滑动高度

     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 }
  • 相关阅读:
    dp学习笔记1
    hdu 4474
    hdu 1158(很好的一道dp题)
    dp学习笔记3
    dp学习笔记2
    hdu 4520+hdu 4522+hdu 4524(3月24号Tencent)
    hdu 1025(最长非递减子序列的n*log(n)求法)
    hdu 2063+hdu 1083(最大匹配数)
    hdu 1023
    《 Elementary Methods in Number Theory 》Exercise 1.3.12
  • 原文地址:https://www.cnblogs.com/farer-zcz/p/4354472.html
Copyright © 2011-2022 走看看