Search code examples
iphonecocoa-touchios4uinavigationbaruinavigationitem

Setting Bar Button Item color in a custom navigation bar


I created a custom navigation bar and a right navigation button using the XIB. This works fine. But I need to to customize the tint color of the right navigation button. At the moment this tint color is the same color as tint color of navigation bar. I need a different color for this right button. Is there any way to change this color?

Thank you.


Solution

  • Not to my knowledge, the button inherits the tint color of the navigationBar. What you can do is set a customView for the navigationItem:

    This is how you set it with one of the SDK's buttons:

    UIBarButtonItem *shareButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(shareButtonHandler:)];
    
    [self.navigationItem setRightBarButtonItem:shareButton];
    [shareButton release];
    

    Instead you can do it like this:

    UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"yourImage.png" style:UIBarButtonItemStyleBordered target:self action:@selector(customButtonHandler:)]];
    

    To use an image you made in photoshop etc.

    There is als an initWithCustomView:UIView or initWithTitle:NSString you can use.

    Sorry no "one-line solution" :)