LukeTerzich
LukeTerzich

Reputation: 554

Change Image opacity when Touched Swift 3 Xcode

I have a play button on my game and when i touch it i would like the image opacity to change or something just so that the user knows they have touched it.

Must be easy for somebody that knows how!

Upvotes: 1

Views: 7204

Answers (2)

2rahulsk
2rahulsk

Reputation: 508

You can animate the button opacity inside the function which is executed when the button is pressed,

UIView.animate(withDuration: 0.2) {

sender.alpha = 0.5

}

UIView.animate(withDuration: 0.2) {

sender.alpha = 1

}

where sender refers to the UIButton.

Upvotes: 0

Mislav Javor
Mislav Javor

Reputation: 1449

The easiest way to change opacity in is to use the UIView alpha property like so:

yourView.alpha = 0.5 // 50% opacity
yourView.alpha = 0 // 0% opacity - completely transparent
yourView.alpha = 1 // 100% opacity - completely opaque

Upvotes: 3

Related Questions