【发布时间】:2011-04-19 12:04:42
【问题描述】:
我是堆栈溢出和可可触摸开发的新手。
我正在尝试使用带有多行 detailTextLabel 的 UITableViewCellSytleValue2 构建 UITableViewCell。
因此我实现了 tableView:heightForRowAtIndexPath: 像这样:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row != 4) {
return tableView.rowHeight;
}
NSString *text = toDoItem.note;
UIFont *font = [UIFont systemFontOfSize:[UIFont systemFontSize]];
CGSize withinSize = CGSizeMake(167, 1000);
CGSize size = [text sizeWithFont:font constrainedToSize:withinSize lineBreakMode:UILineBreakModeCharacterWrap];
CGFloat height = size.height + 26;
return height;
}
我发现 detailTextLabel 的宽度大约为 167 像素,但想准确了解它并且不喜欢硬编码(考虑到方向变化)。
我尝试访问 detailTextLabel 的框架或边界,但它的宽度返回 0.0。
感谢您的帮助!
【问题讨论】:
-
我使用 200px 字体大小为 15。这对我来说很好。
标签: cocoa-touch uitableview multiline