0

I am trying to make a feature where if the user presses the speaker button (a bar button item), then a speaker with a slash through it will replace the original button. Is there an easy way of doing this? I know that it must be done programatically but I can't figure out how to replace the speaker button with a different button.

[Here is a screenshot of my storyboard] : https://i.stack.imgur.com/EL3df.png

rice888
  • 51
  • 8

1 Answers1

1

Add an action for UIBarButtonItem on your UIViewController class by control dragging it into the ViewController's declaration. Then change the item

@IBAction func barButtonAction(_ sender: UIBarButtonItem) {
    sender.image = UIImage(named: "myNewImage")
}
Frankenstein
  • 15,732
  • 4
  • 22
  • 47