UIFont is not convertible 错误
UIFont is not convertible error
我刚刚将我的 swift 2.3 代码转换为 3.0,但是当我尝试更改字体类型时,UILabel 视图突然显示错误。这是错误。它显示 (name: String, size: CGFloat)-> UIFont is not convertible to (name: String, size: CGFloat)-> UIFont?
为什么我不能更改字体类型?我已经清理并构建了项目,但显示相同的错误。这是 UILabel
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
我刚刚将我的 swift 2.3 代码转换为 3.0,但是当我尝试更改字体类型时,UILabel 视图突然显示错误。这是错误。它显示 (name: String, size: CGFloat)-> UIFont is not convertible to (name: String, size: CGFloat)-> UIFont?
为什么我不能更改字体类型?我已经清理并构建了项目,但显示相同的错误。这是 UILabel
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