UIFont不可兑换错误
问题描述:
我刚刚将swift 2.3代码转换为3.0,但突然UILabel视图在尝试更改字体类型时显示错误。这是错误。它表明(name: String, size: CGFloat)-> UIFont is not convertible to (name: String, size: CGFloat)-> UIFont?
为什么我不能更改字体类型?我已经清理并构建了该项目,但显示了相同的错误。这里是的UILabelUIFont不可兑换错误
let placeholder = UILabel()
placeholder.bounds = self.tableView.bounds
placeholder.textAlignment = .Center
placeholder.textColor = UIColor(red: 230.0/255.0, green: 230.0/255.0, blue: 230.0/255.0, alpha: 1.0)
placeholder.font = UIFont(name: "Avenir-Light", size: 15.0)
placeholder.text = "No Events"
self.tableView.backgroundView = placeholder
以下是错误
答
placeholder.font = UIFont(name: "Avenir-Light", size: 15.0)
你应该尝试写这样的:
placeholder.font = UIFont.init(name: "Avenir-Light", size: 15)
更多信息,请参阅this
谢谢!它工作,但为什么我不能写UIFont(名称:“Avenir-Light”,尺寸:15.0)?我为什么要编写init()? –
@ChathurangaSilva - Swift中failable初始化程序更新的问题 –