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;
How to grey out a button to let the user know that it is currently disabled in iOS?
Use following code for customizing button's title for disabled state. You can call it inside viewDidLoad
:
button.setTitleColor(UIColor.grayColor(), forState: .Disabled)
If you would like to customize a background colour for the disabled button, use approach from this answer: How to change background color of UIButton when it's highlighted
Swift 5.3:
button.setTitleColor(.systemGray, for: .disabled)
UIButton tintColor for disabled and enabled state?
You could override the isEnabled property to achieve that. The tintColor will be automatically changed according to the button's isEnabled status:
class ButtonsPostMenu:UIButton {
//......
override var isEnabled: Bool {
didSet{
if self.isEnabled {
self.tintColor = UIColor.white
}
else{
self.tintColor = UIColor.gray
}
}
}
//......
}
UIButton disabled state not changing immediately
You're on the right track about checking the main queue, but your additional processing has to finish before the UI gets a chance to update.
If your code is friendly to this approach, use two dispatch blocks back to the main queue. The first would be your UI-state settings, the second, your remaining processing. This lets the UI state actually update before your additional processing complete.
Pseudocode:
- (IBAction) handlePress:(id)sender {
dispatch_async(dispatch_get_main_queue(), ^{
// Do your state update (button disabled, etc)
});
dispatch_async(dispatch_get_main_queue(), ^{
// Do your further processing - AFTER the ui has been updated
});
}
Related Topics
How to Do Transforms on a Calayer
iOS Keychain Services: Only Specific Values Allowed for Ksecattrgeneric Key
How to Integrate Nsurlconnection with Uiprogressview
Fbsopenapplicationerrordomain Code =4 Error
Avcapturevideopreviewlayer Orientation - Need Landscape
Setting Contentoffset Programmatically Triggers Scrollviewdidscroll
How to Calculate the Age Based on Nsdate
Iphone, Obtaining a List of Countries in an Nsarray
Uipopovercontroller Dealloc Reached While Popover Is Still Visible
How to Create a Release Build in Xcode
How to Correctly Subclass Uicontrol
How to Make Both Header and Footer in Collection View with Swift
Xcode 4.2 Jumps to Main.M Every Time After Stopping Simulator