2017-08-02 79 views
-6

我需要幫助解決Swift 3中的這個錯誤! enter image description hereCGRect.init() - 參數標籤與任何可用的重載不匹配

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 
+4

使用自動完成或檢查文檔以查找可用的過載。 'CGRect'沒有沒有參數標籤的初始化器,因爲你需要告訴編譯器在什麼座標系中/你需要什麼單位來初始化CGRect。 –

回答

1

更換

CGRect(0, 0, 40, 40) 

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

謝謝你的作品!我是新來的迅速 – Techitout

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 

希望它能幫助!

相關問題