Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling a button in iOS

Tags:

ios

uibutton

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.

like image 356
lakshmen Avatar asked Mar 21 '13 04:03

lakshmen


People also ask

How do I make a button disabled?

The disabled attribute is a boolean attribute. When present, it specifies that the button should be disabled. A disabled button is unusable and un-clickable. The disabled attribute can be set to keep a user from clicking on the button until some other condition has been met (like selecting a checkbox, etc.).

How do I block a button after clicking?

There's another way you can disable the submit button after the first click. You can simply remove the onclick event handler by setting its value as null.

How do I disable a button in SwiftUI?

As you can see, the button is disabled just by adding disabled(agreedToTerms == false) to the list of modifiers. Like many other SwiftUI modifiers, you can lift disabled() so that it's run on the section or even the whole form depending on what behavior you want – just move it to come after the section, for example.

How do you disable a button for 30 seconds?

Here use setTimeout, to enable it after 30 seconds. In the anonymus function of setTimeout. Modify the DOM property is also called disabled and is a boolean that takes true or false. Save this answer.


2 Answers

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)

like image 135
Vinayak Kini Avatar answered Oct 17 '22 06:10

Vinayak Kini


Also you can set userInteractionEnabled property of UIButton

 if([self.InfoDictionary objectForKey:ButtonExist])
    {
        [button1 setEnabled:YES];
        button1.userInteractionEnabled = YES;
    }
    else
    {
        [button1 setEnabled:NO];
        button1.userInteractionEnabled = NO;
    }
like image 30
iPatel Avatar answered Oct 17 '22 07:10

iPatel