我正在尝试制作一个UITableViewCell,它可以根据显示的字符串的长度来调整其高度,但是我在这个方法上遇到了麻烦。
下面是我得到的信息:
NSString *text = @"A really long string in here";
CGSize theSize = [text sizeWithFont:[UIFont boldSystemFontOfSize:18.0f] constrainedToSize:CGSizeMake(265.0f, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];
NSString *stringHeight = [NSString stringWithFormat:@"%d", theSize.height];无论如何,stringHeight都会显示为0。我遗漏了什么?
谢谢!
发布于 2009-08-30 00:50:41
CGFloat对应于C float数据类型;它们的适当格式说明符是%f
 NSString *text = @"A really long string in here"; 
 CGSize theSize = [text sizeWithFont:[UIFont boldSystemFontOfSize:18.0f] constrainedToSize:CGSizeMake(265.0f, CGFLOAT_MAX) lineBreakMode:UILineBreakModeWordWrap];
 NSString *stringHeight = [NSString stringWithFormat:@"%f", theSize.height];此外,您应该使用CGFLOAT_MAX而不是MAXFLOAT
发布于 2011-03-11 07:23:18
您还可以使用
NSStringFromCGSize(theSize);https://stackoverflow.com/questions/1352735
复制相似问题