7

In swift, how do I hide a UIButton?

Here's what I tried: button.enabled = false

However, that just greys out the button, not making it invisible.

Is there a way to do it in swift? If so, how?

Thanks!

rocket101
  • 7,369
  • 11
  • 45
  • 64
  • enabled is different to hidden. Enabled gives the user entitlement to use the button, hidden = false means it's visible (conversely hidden = false makes it invisible) – Frankeex Nov 27 '15 at 11:33

3 Answers3

14

Umm… button.hidden = true. See UIView Class Reference.

Be sure to look at methods available in parent classes when reading the documentation for a class.


NOTE: A later version of swift enforced button.isHidden = true as the only option.

Jeffery Thomas
  • 42,202
  • 8
  • 92
  • 117
  • For those investigating how to hide a UIBarButtonItem button, then see this: http://stackoverflow.com/questions/25492491/make-a-uibarbuttonitem-disapear-using-swift-ios – kbpontius May 28 '15 at 22:15
7

For iOS 8+

button.isHidden = true

Apple Documentation

bob.faist
  • 728
  • 7
  • 16
0

I don't know if this is related to your issue but just a tip for others:

If this is for the initial setup:

Make sure that you hide the button within the function ViewWillAppear(animated: Bool)

override func ViewWillAppear(animated: Bool) {
button.hidden = true
} 
nycdanie
  • 2,921
  • 3
  • 18
  • 21