swift – “UIFont”不能转换为“UIFont?
发布时间:2020-12-14 06:06:47 所属栏目:百科 来源:网络整理
导读:所以我今天晚上把我的XCode更新为7.3。 在我的一个项目中,我得到以下错误几个标签,我设置的字体: '(name: String,size: CGFloat) - UIFont' is not convertible to '(name: String,size: CGFloat) - UIFont?' 编辑:这是我的导航栏中的标题视图的代码: l
所以我今天晚上把我的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: "Raisingn$ (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),所以我只是猜测!但是,它将是非常有趣的知道,如果它实际上工作。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |