首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

UILable高度依据内容长度自适应

2012-06-28 
UILable高度根据内容长度自适应方法1.(可用)label.text newTextCGRect bounds label.boundsbounds.s

UILable高度根据内容长度自适应
方法1.(可用)
label.text = newText;

CGRect bounds = label.bounds;

bounds.size = [newText sizeWithFont:label.font];

label.bounds = bounds;


方法2.
+(float) calculateHeightOfTextFromWidth:(NSString*) text: (UIFont*)withFont: (float)widthUILineBreakMode)lineBreakMode
{
[text retain];
[withFont retain];
CGSize suggestedSize = [text sizeWithFont:withFont constrainedToSize:CGSizeMake(width, FLT_MAX) lineBreakMode:lineBreakMode];

[text release];
[withFont release];

return suggestedSize.height;
}

热点排行