1

I need to change color on the default "self.navigationItem.backBarButtonItem". To accomplish this I´ve created an custom Button class and implemented it like this:

- (void)viewDidLoad {
[super viewDidLoad];    
BackButton *blueSaveButton = [[BackButton alloc] init];
UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:blueSaveButton];
temporaryBarButtonItem.title = @"Tillbaka";
self.navigationItem.backBarButtonItem = temporaryBarButtonItem;
[temporaryBarButtonItem release];
[blueSaveButton release];
[self gotoLocation];

}

But this has no effect at all on the button. So how do you manage to do this without "breaking" the default/inherited behavior of the navigationbar?

EDIT: The reason is that the button needs to be corporate branded, so default styles will not do.

BR

Christofffer
  • 413
  • 1
  • 5
  • 15

2 Answers2

1

If you want the button to be blue (like a Done button) and have the title "Save" you can use one of the built in bar button item types:

UIBarButtonItem *item = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(myAction:)] autorelease];
Jasarien
  • 58,279
  • 31
  • 157
  • 188
  • That was fast. I need to set a custom color or image (corporate branded). This is really one heavy downside of iPhone development that this kind of simple task needs heavy customizing of a simple control. – Christofffer Jul 21 '10 at 10:02
  • In that case you'll have to use an image. Create a `UIButton`, set it's title and background image properties using the `setTitle:forState:` and `setBackgroundImage:forState` methods and then create the `UIBarButtonItem` with the `UIButton` instance as a custom view. As far as I'm aware, setting a background colour on a button isn't enough. – Jasarien Jul 21 '10 at 10:10
  • I have already done that in BackButton controller. The inference I draw is that NavigationBarItem overrides my custom controller. – Christofffer Jul 21 '10 at 10:23
0

Ok found the solution (not so good but it works) do this: 1: Implement the button from this tutorial: www.switchonthecode.com

This will override the default behavior of navigationbar.

2: Implement this in every view that needs the custom button: osmorphis.blogspot.com

BR

Christofffer
  • 413
  • 1
  • 5
  • 15