Search code examples
swiftbuttonuikitalpha

Button doesn't trigger action when the alpha is 0


I have a button that working fine when his alpha is 1, but when I set the alpha to 0, it doesn't do the functions. (I want the button to be invisible, but still responsive). how do I fix that?

thanks!


Solution

  • Setting the alpha of a UIButton to zero will not allow getting any touch events from it.

    Instead, you can keep the alpha 1.0 and set the background color to UIColor.clear, and the text to "" (empty). This way, the button will be invisible like you asked, but still tappable.