今天晚上我更新了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编写的Attributed String代码:
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
这种情况只发生在我的整个项目中的两个文件中。
我打开了另一个项目,但是即使我在那里也为多个标签设置了字体,但我仍然能够成功构建和运行它,没有任何错误。
有任何想法为什么会发生这种情况吗?
谢谢!
aAttributedFundLabel
?阿达·洛夫莱斯的幽灵会惩罚你的... - vikingosegundo