Robert Young Robert Young - 1 month ago 5x
iOS Question

How to make an UIButton optional using storyboard?

I need to make a Button optional based on data coming from the server.
It's easy when building UI programmatically. Like,

if ( flag == 1)
// Build the UIButton

But I am new to storyboard and company wants to build the UI this way. So I was wondering how to make the button optional? Thanks in advance.


You can do it like this:

In your .h file declare your property

@property(nonatomic, weak) IBOutlet UIButton *yourBtn;

Link this property to your button in storyboard

In your .m file

 [super ViewDidLoad];
 [self.yourBtn setHidden:YES];

Later on in your code if you need to enable your button just call

[self.yourBtn setHidden:NO];