Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoiding making a UIButton transparent/see-through when disabling it

I want to disable my UIButton, so I call:

button.enabled = FALSE;

However this makes the button see-through and I can see the elements underneath it. I don't mind that it changes colour, I just don't want it to be see-through.

I've tried ticking the boxes for 'opaque' and 'clip subviews' in IB, but no joy.

Is there an easy way to fix this? I suppose I could put a UIImageView with the same button image behind it, but it's hardly an elegant solution.

like image 551
Smikey Avatar asked Aug 12 '10 11:08

Smikey


People also ask

Is it ok to grey out disabled buttons?

For a smooth and seamless experience, it's best to avoid graying out your disabled buttons. Instead, you should decrease the opacity to make it transparent. When the disabled button is transparent, users can see some semblance of the button in its enabled state.

What is the color of disabled button?

Imagine a world in which every button is disabled by default. Usually it's grey, subtle and slightly out of focus, often with poor contrast and a subdued text label that's a bit difficult to decipher.

How do I disable UI button?

In this Swift code example, you will learn how to disable UIButton. The quickest way to disable the button in Swift is to simply set the button's isEnabled property to false. For example button. isEnabled = false.

What is UIButton in xcode?

A control that executes your custom code in response to user interactions.


2 Answers

You can also do:

button.adjustsImageWhenDisabled = NO;
like image 178
Snowman Avatar answered Sep 17 '22 21:09

Snowman


Try userInteractionEnabled property:

button.userInteractionEnabled = NO;
like image 22
jamapag Avatar answered Sep 19 '22 21:09

jamapag