swift – “UIFont”不能转换为“UIFont?

所以我今天晚上把我的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字符串的代码

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)!,length: 7)) // ERROR POPS UP HERE 
aAttributedFundLabel.addAttribute(NSForegroundColorAttributeName,value: UIColor.blackColor(),range: NSRange(location: 8,length: fund.characters.count + 2))
aAttributedFundLabel.addAttribute(NSFontAttributeName,size: 16)!,length: fund.characters.count + 2)) // ERROR POPS UP HERE
startupFund.attributedText = aAttributedFundLabel

这只发生在我的整个项目中的两个文件

我打开了另一个项目,但我能够构建和运行它没有任何错误,即使我设置了多个标签的字体,以及。

任何想法为什么这是发生?

TIA!

在SO的其他地方,有人建议你在这里
aTitleView.font = UIFont(name: "Roboto-Regular",size: 15)

…你应该试试这样写:

aTitleView.font = UIFont.init(name: "Roboto-Regular",size: 15)

我可以不承担这个(因为我不能重现的bug),所以我只是猜测!但是,它将是非常有趣的知道,如果它实际上工作。

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...