按照教程,我正在使用新的 UIButtons 和 iOS 15。
let btn = UIButton(frame:CGRect(x: 25, y:0 , width: 250, height: 50))
btn.config.title = "Connect"
btn.updateConfiguration()
btn.configurationUpdateHandler = { button in
var config = btn.configuration
switch button.state {
case .highlighted:
config?.showsActivityIndicator = true
config?.imagePadding = 5
self.role = self.nameInput.text?.lowercased()
UserDefaults.standard.set(self.role, forKey: "role")
SFSConn.shared.connect()
default:
config?.showsActivityIndicator = false
}
btn.configuration = config
}
btnForm.addSubview(btn)
如何將閉包推斷為獨立閉包?我想將多個按鈕連接到同一個閉包。提前致謝。
uj5u.com熱心網友回復:
該configurationUpdateHandler
屬性屬于 type UIButton.ConfigurationUpdateHandler?
,它只是 for的型別別名(UIButton) -> Void
,它是一個接受單個引數 的閉包UIButton
。所以只需創建它。
let handler: (UIButton) -> Void = { (button) in
// do something
}
btn.configurationUpdateHandler = handler
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/384066.html
上一篇:ios影像和標簽在滾動時保持加載