When setting the right navigation bar button to disabled, it does not change its color to signal its disabled state to the user.
It remains "highlighted", non-greyed-out.
I have set up the button in Storyboard as follows:
self.navigationController.navigationItem.rightBarButtonItem.enabled = NO;
What do I need to do to change the button`s state visually too?
Thank you!
Update it to:
self.navigationItem.leftBarButtonItem?.isEnabled = true
Credit to Vijay-Apple-Dev.blogspo for this answer.
self.navigationItem.leftBarButtonItem.enabled = NO;
self.navigationItem.rightBarButtonItem.enabled = NO;
This automatically seems to grey out the buttons and also disables them.
NOTE: The assumption in the question that self.navigationController.navigationItem.rightBarButtonItem.enabled = NO; works seems to be wrong, after trialling it in my code I found it had no effect.
Again thanks to Vijay noting that it might be better to use:
self.navigationItem.hidesBackButton = YES;
As Apple doesn't like disabling the back button.
Personally I am going to disable the top right button and hide the back button to stop the user from pressing them, then enable them again when I choose.
A link to the question is here
This answer is posted for completeness and so future users don't need to continue searching past this page.
None of the relevant answers were able to produce the result I was looking for - but I was able to solve this by setting the text attributes on my navigation buttons:
[navButton setTitleTextAttributes:@{NSForegroundColorAttributeName:enabledColor} forState:UIControlStateNormal];
[navButton setTitleTextAttributes:@{NSForegroundColorAttributeName:disabledColor} forState:UIControlStateDisabled];
Then, all I need to do is the following and the user interactability and color changes automatically:
navButton.enabled = YES; // or NO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With