标签:
在实际的代码应用中,我们常常需要计算,特定文本的宽度和高度。然后,根据长度和宽度值,动态的设置容器(如:UILabel)的长和宽来进行适应。UIFont *theFont = [UIFont systemFontOfSize:14];
NSString *strText = @"这是一段很长的字符串,我们将根据要求的字体大小,来计算实际需要的宽度和高度!";
NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObject:[UIFont systemFontOfSize:14] forKey:NSFontAttributeName]; CGSize size = [strText boundingRectWithSize:CGSizeMake(MAXFLOAT, 0.0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObject:[UIFont systemFontOfSize:14] forKey:NSFontAttributeName]; CGSize size = [strText boundingRectWithSize:CGSizeMake(100.0, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
typedef NS_ENUM(NSInteger, NSLineBreakMode) {
}NS_ENUM_AVAILABLE_IOS(6_0);
标签:
原文地址:http://blog.csdn.net/u010130947/article/details/42552179