微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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),所以我只是猜测!但是,它将是非常有趣的知道,如果它实际上工作。

原文地址:https://www.jb51.cc/swift/321174.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐