iosuibutton

Disabling a button in iOS


I need to disable a button if the key does not exist in the dictionary. I have used the setEnabled functionality of the UIButton but the image that has been set default still appears.

The code looks like this:

if([self.InfoDictionary objectForKey:ButtonExist])
{
    [button1 setEnabled:YES];
}
else
{
    [button1 setEnabled:NO];
}

The image still appears when I run in the simulator. Need some guidance on this.


Solution

  • enable = YES property of button performs the action when clicked.

    enable = NO property prevents action to be executed on click.

    If you want to hide the button then you can set the hidden property as YES or vice versa. Other way to hide is by setting the alpha property to 0 (invisible) or 1 (visible)