iphonenavigationbarrightbarbuttonitemnavigationitem

disable bar button text color changes to white?


Given below is image of my navigation bar, where right bar button is disable now. but when i disable it its text changes to white color. i don't want white color. Any solution of this.

First image when Edit button is enabled. Other when Edit button is disabled. Can we disable button without changes its text color in that case. many thanks in advance

this is for customizing bar button

 [[UIBarButtonItem appearance] setTintColor:[UIColor colorWithRed:253.0/255.0 green:220.0/255.0 blue:135.0/255.0 alpha:1.0]];


[[UIBarButtonItem appearance] setTitleTextAttributes:
 [NSDictionary dictionaryWithObjectsAndKeys:
  [UIColor blackColor], UITextAttributeTextColor,
  [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0], UITextAttributeTextShadowColor,
  [UIFont fontWithName:@"MyriadPro-Cond_0" size:16.0], UITextAttributeFont, nil]
                                            forState:UIControlStateNormal];

this is for bar button

 UIBarButtonItem *rightBarBtnEdit=[[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStyleBordered target:self action:@selector(methodEdit:)];
[rightBarBtnEdit setTag:701];
[self.navigationItem setRightBarButtonItem:rightBarBtnEdit];

this is disabling

    self.navigationItem.rightBarButtonItem.enabled = NO;

enter image description here

enter image description here


Solution

  • setTitleTextAttributes:forState: should be called multiple times, for each state you wish to customise. At the moment you're calling it once, for UIControlStateNormal, for other states the values will be at their default.

    Call it with UIControlStateDisabled as well, with whatever attributes you need.