如何从函数参数访问 ViewController Class 中的 UIButton

How can I access an UIButton in the ViewController Class from a function parameter

如何从具有 2 个参数的函数访问 IBOutlet UIButton

class ViewController: UIViewController {

@IBOutlet weak var btnMaxAloud: UIButton!

 override func viewDidLoad() {
 
 
   btnMaxAloud.tintColor = UIColor.white

   changeIconColor(btnMaxAloud , red) // this is gets the error has no member 
     
 }

 func changeIconColor(_ uIButtonName:String , _ color:String){
     if varName {
         self.uIButtonName.tintColor = UIColor.color
     }
  }

您的代码有误,特别是 changeIconColor 的参数类型。例如,这应该有效:

class ViewController: UIViewController
{
    @IBOutlet weak var btnMaxAloud: UIButton!

    override func viewDidLoad()
    {
        btnMaxAloud.tintColor = UIColor.white
        changeIconColor(btnMaxAloud, UIColor.red)
    }

    func changeIconColor(_ button: UIButton, _ color: UIColor)
    {
        button.tintColor = color
    }
}

函数 changeIconColor() 现在接受 UIButtonUIColor 作为参数。

func changeIconColor(uIButtonName: UIButton, color: UIColor) {
    uIButtonName.tintColor = color
}

现在在 viewDidLoad 中

changeIconColor(uIButtonName: btnMaxAloud, color: .red)