1

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

borna
  • 906
  • 3
  • 12
  • 32

2 Answers2

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?

Community
  • 1
  • 1
Warfield
  • 39
  • 1
  • 5
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