我收到了一個警告:「'sizeWithFont:constrainedToSize:lineBreakMode:'已棄用:iOS 7.0以前不推薦使用」 任何人都可以請建議我一種替代方法嗎?sizeWithFont:在iOS 7
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Calculate height based on cell content — cell content will stretch appropriately when the height is set
Post *post = self.articleComments[indexPath.row];
CGFloat width = tableView.frame.size.width - 71 - 15; // Width of comment text area
UIFont *commentFont = [UIFont fontWithName:@"SeroCompPro-Light" size:14];
CGFloat commentTextHeight = [post.text sizeWithFont:commentFont constrainedToSize:CGSizeMake(width, 10000) lineBreakMode:NSLineBreakByWordWrapping].height;
return commentTextHeight + 31 + 37;
}
[Replacement for deprecated sizeWithFont:in iOS 7?](http://stackoverflow.com/questions/18897896/replacement-for-deprecated-sizewithfont-in-ios -7) – Amar
是的,但那是CGRect,我需要CGFloat。 – Alex
請檢查我的答案 http://stackoverflow.com/questions/18903304/deprecated-in-ios-7-sizewithfont-constrainedtosize-linebreakmode-how-can/19045079#19045079 – svrushal