0

I am trying to make a settings page where if you select the 'Red' theme, then the red button's background goes red and the 'Blue' theme button's background goes white and vice versa. My problem is that I do not know how to edit another UIButton outside of the actual UIButton code. I know to edit the background color of regular UIButton you would write:

sender.backgroundColor = .red

However I am not sure how to do this outside the UIButton's code.

I have tried this:

themeCRed(sender.backgroundColor = .white)

(ThemeCRed is the button's name)

But I get the error, "Cannot convert value of type '()' to expected argument type 'UIButton'"

How can I edit the attributes of the other UIButton outside of it's function block?

Richard
  • 57
  • 4
  • 10

3 Answers3

0

If you know the intended outcome and there's few variations then forget about the sender and just set the intended uicolor to the desired uicolor

mrabins
  • 197
  • 1
  • 2
  • 10
0

You just need to identify the event of theme change and need to change the background colour of the buttons like below

yourButton.backgroundColor = UIColor.red
Maulik Pandya
  • 2,200
  • 17
  • 26
0

I don't sure that i understand you correct, but may be just make

@IBOutlet var myButton: UIButton!

in your ViewController or something... and

myButton.backgroundColor = .white

hm?

Daivest
  • 66
  • 4