Disabled UIButton not faded or grey
Disabled UIButton not faded or grey
In my iPhone app, I have a UIButton which I have created in Interface Builder. I can successfully enable and disable it like this in my code ...
sendButton.enabled = YES;
or
sendButton.enabled = NO;
However, the visual look of the button is always the same! It is not faded or grey. If I attempt to click it though, it is enabled or disabled as expected. Am I missing something? Shouldn't it look faded or grey?
thanks
Answer by Jhaliya for Disabled UIButton not faded or grey
Try to set the different images for UIControlStateDisabled
(disabled gray image) and UIControlStateNormal
(Normal image) so the button generate the disabled state for you.
Answer by Ravin for Disabled UIButton not faded or grey
You can use following code:
sendButton.enabled = YES; sendButton.alpha = 1.0; or sendButton.enabled = NO; sendButton.alpha = 0.5;
Answer by guywithmazda for Disabled UIButton not faded or grey
Another option is to change the text color (to light gray for example) for the disabled state. In the storyboard editor, choose Disabled from the State Config popup button, and use the Text Color popup button to change the text color. In code, use the -setTitleColor:forState: message.
(I realize this is an older post, but I thought others might like this option)
Answer by ChavirA for Disabled UIButton not faded or grey
You can use the both first answers and is going to be a better result.
In the attribute inspector (when you're selecting the button), change the State Config to Disabled to set the new Image that is going to appear when it is disabled (remove the marker in the Content->Enabled check to made it disabled).
And when you change the state to enabled, the image will load the one from this state.
Adding the alpha logic to this is a good detail.
Greetings!
Answer by Antonio Moro for Disabled UIButton not faded or grey
If you use a text button, you can put into viewDidLoad the instance method
- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state
example:
[self.syncImagesButton setTitleColor:[UIColor grayColor] forState:UIControlStateDisabled];
Answer by King-Wizard for Disabled UIButton not faded or grey
In Swift:
previousCustomButton.enabled = false previousCustomButton.alpha = 0.5
or
nextCustomButton.enabled = true nextCustomButton.alpha = 1.0
Answer by user4179639 for Disabled UIButton not faded or grey
#import "UIButton+My.h" #import @implementation UIButton (My) -(void)fade :(BOOL)enable{ self.enabled=enable;// self.alpha=enable?1.0:0.5; } @end
.h:
#import @interface UIButton (My) -(void)fade :(BOOL)enable; @end
Answer by Yichao Lu for Disabled UIButton not faded or grey
I am stuck on the same problem. Setting alpha is not what I want.
UIButton
has "background image" and "background color". For image, UIButton
has a property as
@property (nonatomic) BOOL adjustsImageWhenDisabled
And background image is drawn lighter when the button is disabled. For background color, setting alpha, Ravin's solution, works fine.
First, you have to check whether you have unchecked "disabled adjusts image" box under Utilities-Attributes.
Then, check the background color for this button.
(Hope it's helpful. This is an old post; things might have changed in Xcode).
Answer by Ahmed R. for Disabled UIButton not faded or grey
just change state config to disable and choose what you want, background color OR background Image for disabled state
Answer by Mahesh Lad for Disabled UIButton not faded or grey
You can use adjustsImageWhenDisabled
which is property of UIButton
(@property (nonatomic) BOOL adjustsImageWhenDisabled)
Ex:
Button.adjustsImageWhenDisabled = false
Answer by Diego A. Rincon for Disabled UIButton not faded or grey
This is quite an old question but there's a much simple way of achieving this.
myButton.userInteractionEnabled = false
This will only disable any touch gestures without changing the appearance of the button
Answer by AechoLiu for Disabled UIButton not faded or grey
If the UIButton
is in the state combined with selected
and disabled
, it's state is UIControlStateSelected | UIControlStateDisabled
.
So, it's state needs to adjust by
[button setTitleColor:color UIControlStateSelected | UIControlStateDisabled]; [button setImage:image forState:UIControlStateSelected | UIControlStateDisabled];
An approach is sub-class UIButton
as following.
@implementation TTButton - (void)awaeFromNib { [super awakeFromNib]; //! Fix behavior when `disabled && selected` //! Load settings in `xib` or `storyboard`, and apply it again. UIColor *color = [self titleColorForState:UIControlStateDisabled]; [self setTitleColor:color forState:UIControlStateDisabled]; UIImage *img = [self imageForState:UIControlStateDisabled]; [self setImage:img forState:UIControlStateDisabled]; } - (void)setTitleColor:(UIColor *)color forState:(UIControlState)state { [super setTitleColor:color forState:state]; // if (UIControlStateDisabled == state) { [super setTitleColor:color forState:UIControlStateSelected | state]; [super setTitleColor:color forState:UIControlStateHighlighted | state]; } } - (void)setImage:(UIImage *)image forState:(UIControlState)state { [super setImage:image forState:state]; if (UIControlStateDisabled == state) { [super setImage:image forState:UIControlStateSelected | state]; [super setImage:image forState:UIControlStateHighlighted | state]; } } @end
Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72
0 comments:
Post a Comment