IOS 7 sizeWithFont已弃用 [英] IOS 7 sizeWithFont Deprecated

查看:138
本文介绍了IOS 7 sizeWithFont已弃用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法正确地用 boundingRecWithSize 替换已弃用的 sizeWithFont 。我仔细检查了所有的答案并熬夜试图解决这个问题。我真的需要一些比我更聪明的人的帮助。这是我试图修改的代码。任何帮助将不胜感激。

I cannot seem to replace the deprecated sizeWithFont with boundingRecWithSize correctly. I scoured through all the answers and stayed up all night trying to fix this.I really need help from someone way smarter than I. Here is the code I am trying to modify. Any help would be appreciated.

CGSize sizeForText = [faqItem.answer sizeWithFont:[UIFont boldSystemFontOfSize:14]
   constrainedToSize:CGSizeMake(self.tblView.bounds.size.width - padding, MAXFLOAT)
   lineBreakMode:NSLineBreakByWordWrapping];

[sectionInfo insertObject:[NSNumber numberWithFloat:roundf(sizeForText.height + 5)]
  inRowHeightsAtIndex:0];


推荐答案

在apple 文档


sizeWithFont:返回字符串的大小,如果要将其渲染为
在一行上指定字体。 (在iOS 7.0中不推荐。使用
sizeWithAttributes:改为。)


  • (CGSize)sizeWithFont: (UIFont *)font Parameters font用于计算字符串大小的字体。返回值
    的宽度和高度结果字符串的边界框。这些值可以四舍五入到最近的整数

所以你可以使用 sizeWithAttributes:像这样:

So you can use sizeWithAttributes: like this:

 CGSize sizeForText = [faqItem.answer sizeWithAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:14]}
                       constrainedToSize:CGSizeMake(self.tblView.bounds.size.width - padding, MAXFLOAT) 
                           lineBreakMode:NSLineBreakByWordWrapping];

[sectionInfo insertObject:[NSNumber numberWithFloat:roundf(sizeForText.height + 5)] 
      inRowHeightsAtIndex:0];

这篇关于IOS 7 sizeWithFont已弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆