所以我今天晚上把我的XCode更新到7.3了。
在我的一个项目中,对于设置字体的少数标签,我得到以下错误:
'(name: String, size: CGFloat) -> UIFont' is not convertible to '(name: String, size: CGFloat) -> UIFont?'编辑:--这是我在导航栏中的标题视图代码:
let aTitleFrame: CGRect = CGRectMake(0, aHeaderTitleSubtitleView.frame.midY / 2, 200, 24)
let aTitleView: UILabel = UILabel(frame: aTitleFrame)
aTitleView.backgroundColor = UIColor.clearColor()
aTitleView.font = UIFont(name: "Roboto-Regular", size: 15) // ERROR POPS UP HERE
aTitleView.textAlignment = NSTextAlignment.Center
aTitleView.textColor = UIColor.whiteColor()这是UILabel属性化字符串的代码:
let aAttributedFundLabel: NSMutableAttributedString = NSMutableAttributedString(string: "Raising\n$ \(fund)")
aAttributedFundLabel.addAttribute(NSForegroundColorAttributeName, value: UIColor.darkGrayColor(), range: NSRange(location: 0, length: 7))
aAttributedFundLabel.addAttribute(NSFontAttributeName, value: UIFont(name: "Roboto-Regular", size: 15)!, range: NSRange(location: 0, length: 7)) // ERROR POPS UP HERE
aAttributedFundLabel.addAttribute(NSForegroundColorAttributeName, value: UIColor.blackColor(), range: NSRange(location: 8, length: fund.characters.count + 2))
aAttributedFundLabel.addAttribute(NSFontAttributeName, value: UIFont(name: "Roboto-Regular", size: 16)!, range: NSRange(location: 8, length: fund.characters.count + 2)) // ERROR POPS UP HERE
startupFund.attributedText = aAttributedFundLabel这种情况只发生在我整个项目中的两个文件中。
我打开了另一个项目,但是我能够在没有任何错误的情况下构建和运行它,尽管我也为多个标签设置了字体。
知道为什么会这样吗?
蒂娅!
发布于 2016-03-23 04:01:56
在其他地方,有人建议你在哪里有这样的东西:
aTitleView.font = UIFont(name: "Roboto-Regular", size: 15)...you应该尝试这样写:
aTitleView.font = UIFont.init(name: "Roboto-Regular", size: 15)我对此没有任何功劳(因为,我不能复制bug),所以我只是猜测!但是如果知道它是否真的有效的话,那将是非常有趣的。
发布于 2016-03-31 15:58:42
我也有这个问题。为我修正的是关闭整个模块优化。
Bulid设置>快速编译器-代码生成>优化级别
我把它设置为最快的(整个模块优化)。当我把它设置为零时,我就不再有这个问题了。对于上下文,这是一个目标C和Swift的混合代码库。
https://stackoverflow.com/questions/36163273
复制相似问题