CGRect.init() - 参数标签与任何可用的重载都不匹配

时间:2017-08-02 09:33:30

标签: swift

我需要帮助解决Swift 3中的这个错误! enter image description here

let button = UIButton(frame: CGRect(0, 0, 40, 40)) // Create new button & set its frame
button.setImage(UIImage(named: "refresh"), for: []) // Assign an image
barButton.customView = button // Set as barButton's customView

2 个答案:

答案 0 :(得分:3)

替换

CGRect(0, 0, 40, 40)

CGRect(x: 0, y: 0, width: 40, height: 40)

答案 1 :(得分:0)

使用此代码 -

        let button = UIButton(frame: CGRect(x: 0, y: 0, width: 40, height: 40)) // Create new button & set its frame
        button.setImage(UIImage(named: "refresh"), for: []) // Assign an image
        barButton.customView = button // Set as barButton's customView

希望它有所帮助!