我在使用 UIFont
时也遇到了这个错误:
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor(), NSFontAttributeName:UIFont(name: "AvenirNextCondensed-DemiBold", size: 22.0)]
有人知道我该如何解决这个问题吗?我尝试将 22.0 转换为 CGFloat
但没有效果
最佳答案
这是因为 UIFont
初始化可能会失败并返回 nil。尝试:
if let font = UIFont(name: "AvenirNextCondensed-DemiBold", size: 22.0) {
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor(), NSFontAttributeName: font]
}
关于ios - 找不到接受提供的参数的 "init"的重载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26398305/