【发布时间】:2012-11-05 11:01:20
【问题描述】:
我有一个表格视图,其中我的单元格高度是根据它所代表的文本动态定义的。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//getting my text for this cell, the row etc ...
...
//here is the part interesting us
NSAttributedString* theText = [myTextForThisCell objectAtIndex:indexPath.row];
NSInteger labelWidth = self.tableView.bounds.size.width-HORIZONTAL_CELL_PADDING;
CGSize textSize = [theText sizeWithFont:[UIFont systemFontOfSize:customFontSize] constrainedToSize:CGSizeMake(labelWidth, MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping];
return textSize.height+VERTICAL_CELL_PADDING;
}
好的,现在我的问题。 tableview 是搜索操作的结果,它在扫描 plist 文件后显示包含给定字符串的行。
到现在为止就是这样。但是现在有了 iOS 6 和 NSAttributedString 可以轻松地将部分字符串加粗,我决定将搜索词加粗。
它正在工作,它加粗了我想要的单词,但现在我不再能够计算单元格高度,因为 sizeWithFont 要求一个 NSString。而且由于粗体需要更宽的宽度,我不能简单地用没有属性的字符串计算单元格高度。
我只是卡在这里。
谁能帮帮我?
【问题讨论】:
标签: ios6 uitableview ios7