How Can i access an IBOutlet UIButton from a function with 2 param
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
}
}
Your code is wrong, specifically the argument types for changeIconColor
. For example this should work:
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
}
}
The function changeIconColor()
now takes a UIButton
and UIColor
as argument.