如何在点击执行功能之前显示 LGButton 的加载微调器?

How to show loading spinner of LGButton before executing function on click?

我正在使用 https://github.com/loregr/LGButton。我得到了触发功能等的按钮,但如何使用此库的加载微调器 UI?一旦我也启用它,它只会显示几毫秒,因为单击按钮时功能会快速触发

@IBAction func theFunction(_ sender: LGButton) {
       
        let alertView = SCLAlertView()
        alertView.addButton("Y button", target: self, selector: #selector(self.generateNewNumber))
        alertView.addButton("X Button", target: self, selector: #selector(self.zfunction))

        alertView.showSuccess("", subTitle: ""])

    }
  
    
    @IBOutlet var instanceofLGButton: LGButton!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationController?.interactivePopGestureRecognizer?.isEnabled = true
        self.view.backgroundColor = UIColor.black 
        instanceofLGButton.addTarget(self, action: #selector(self.learning(_:)), for: .touchUpInside)

谢谢。代码的相关部分在上面。

当您将 isLoading 参数设置为 true 时,它会显示微调器。

    @IBAction func action(_ sender: LGButton) {
        sender.isLoading = true
        let deadlineTime = DispatchTime.now() + .seconds(3)
        DispatchQueue.main.asyncAfter(deadline: deadlineTime) {
            sender.isLoading = false
            // DO SOMETHING
        }
    }