I have a button with background image and need to set the alpha to 0.5. How can I do this in swift?
This is my code that set the button background image
centerButton.setBackgroundImage(UIImage(named: "buttonImage"), forState: UIControlState.Normal)
Thanks
Asked
Active
Viewed 4,570 times
2 Answers
0
I think you must create UIImage instance first and change alpha, then, setBackgroundImage to your button.
You can check: How to set the opacity/alpha of a UIImage?
0
if you want to set alpha on only background image, then re-create UIImage with changing the alpha value.
if you want to set alpha to entire button, then simply set alpha value to the button.
centerButton.alpha = 0.5

Joey
- 2,912
- 2
- 27
- 32