UIFont不可转换错误

时间:2016-09-21 09:28:15

标签: ios swift swift3 uifont

我刚刚将我的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

这是错误

enter image description here

1 个答案:

答案 0 :(得分:2)

placeholder.font = UIFont(name: "Avenir-Light", size: 15.0)

你应该尝试写这个:

placeholder.font = UIFont.init(name: "Avenir-Light", size: 15)

有关详细信息,请参阅this