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.e
It looks like the following code works fine. But in some cases, this doesn't work.
sendButton.enabled = NO;
sendButton.alpha = 0.5;
If the above code doesn't work, please wrap it in Main Thread. so
dispatch_async(dispatch_get_main_queue(), ^{
sendButton.enabled = NO;
sendButton.alpha = 0.5
});
if you go with swift, like this
DispatchQueue.main.async {
sendButton.isEnabled = false
sendButton.alpha = 0.5
}
In addition, if you customized UIButton, add this to the Button class.
override var isEnabled: Bool {
didSet {
DispatchQueue.main.async {
if self.isEnabled {
self.alpha = 1.0
}
else {
self.alpha = 0.5
}
}
}
}
Thank you and enjoy coding!!!