i wrote in my code
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor lightGrayColor], NSFontAttributeName:[UIFont boldSystemFontOfSize:16.0f]} forState:UIControlStateDisabled];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor blueColor], NSFontAttributeName:[UIFont boldSystemFontOfSize:16.0f]} forState:UIControlStateNormal];
but the text color is always blue despite the baritem being disabled.
I'm programming in xcode 5 and ios7
for me following code
works.
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem * btnTemp = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(btnDone_Click:)];
[btnTemp setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor lightGrayColor], NSFontAttributeName:[UIFont boldSystemFontOfSize:16.0f]} forState:UIControlStateNormal];
[btnTemp setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor blueColor], NSFontAttributeName:[UIFont systemFontOfSize:16.0f]} forState:UIControlStateDisabled];
[self.navigationItem setRightBarButtonItem:btnTemp];
}
- (void)btnDone_Click : (id)sender {
UIBarButtonItem * button = (UIBarButtonItem *)sender;
[button setEnabled:FALSE];
[self performSelector:@selector(enableButton:) withObject:sender afterDelay:2.0f];
}
- (void)enableButton : (id)sender {
UIBarButtonItem * button = (UIBarButtonItem *)sender;
[button setEnabled:TRUE];
}
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