`

计算label的高度

    博客分类:
  • iOS
阅读更多

//http://blog.sallarp.com/iphone-uilabel-multiline-dynamic-height/


- (float) calculateHeightOfTextFromWidth:(NSString*) text: (UIFont*)withFont: (float)width :(UILineBreakMode)lineBreakMode
{
    [text retain];
    [withFont retain];
    CGSize suggestedSize = [text sizeWithFont:withFont constrainedToSize:CGSizeMake(width, FLT_MAX) lineBreakMode:lineBreakMode];
   
    [text release];
    [withFont release];
   
    return suggestedSize.height;
}

 

 

另外计算label高度的代码

http://desheng.me/2010/10/03/iphone%E5%BC%80%E5%8F%91%E5%9F%BA%E7%A1%80%E9%97%AE%E9%A2%98%E6%80%BB%E7%BB%93/

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics