在Xcode 5上将一个项目从iOS5.0升级到iOS7 / iOS6。下面的代码会产生编译时警告:
'sizeWithFont:constrainedToSize:lineBreakMode:'已弃用:自iOS 7.0起首次弃用-使用-boundingRectWithSize:options:attribiutes:context
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0)
{
self.lblHidden.frame = CGRectMake(58, 228, 945, 9999);
self.lblHidden.text = detailShareObj.pDesc;
CGSize size = [detailShareObj.pDesc sizeWithFont:self.lblHidden.font constrainedToSize:self.lblHidden.frame.size lineBreakMode:NSLineBreakByWordWrapping];
return 228.0+size.height+20;
}
else if (indexPath.section == 1)
{
NSString *tempPointStr = (self.shortDescArray)[indexPath.row];
self.lblHidden.frame = CGRectMake(58, 0, 945, 9999);
self.lblHidden.text = tempPointStr;
CGSize size = [tempPointStr sizeWithFont:self.lblHidden.font
constrainedToSize:self.lblHidden.frame.size
lineBreakMode:NSLineBreakByWordWrapping];
return 50.0f;
}
我尝试了其他地方提供的建议,但如果有人能帮忙提供代码所需的更正,将不胜感激。
CGRectIntegral(rect)
要比分别对高度和宽度进行向上取整更加简洁。这样可以使得尺寸更加整齐。 - memmonsboundingRectWithSize
在使用NSStringDrawingUsesLineFragmentOrigin
时总是使用换行规则NSLineBreakByClipping
,因此当我们使用其他换行规则时,它会返回不正确的大小。例如:NSLineBreakByCharWrapping
。 - jeeeyul