我正在尝试制作一个 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
。我缺少什么?
Thanks!
CGFloat
s对应于Cfloat
数据类型;它们的正确格式说明符是%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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)