【发布时间】:2014-08-28 05:09:19
【问题描述】:
我在 UITableViewCell 中有一个 UILabel。 UILabel 的高度取决于使用自动布局约束的 UITableViewCell 的高度。 UILabel 的宽度是176.0 并且是固定的。
我在 UILabel 中使用 boundingRectWithSize:options:attributes:context: 来确定 UITableViewCell 的高度。
这里是显示界面生成器中的 UILabel 配置的屏幕截图
这是获取 UILabel 文本的 boundingRect 的代码。
NSString *text = @"Extra long goods charge";
CGSize maxSize = CGSizeMake(176.0f, MAXFLOAT);
CGRect rect = [text boundingRectWithSize:maxSize
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16.0]}
context:nil];
返回的大小为152.132813, 18.1796875,但此矩形不够大,无法包含Extra long goods charge 文本。事实上,即使是176, 18 大小的矩形也不能包含此文本。
我的猜测是我在使用boundingRectWithSize
【问题讨论】:
标签: ios objective-c ios7 nsstring