0

Well, I have a NavigationController with a diferent color and I want the back button to also have a background image, a highlighted background image, and a custom text color. How can I do this? I have tried lots of things but I havent been able to change this backbutton.

sergiocg90
  • 479
  • 2
  • 11
  • 24

1 Answers1

1

I guess you have to create your own custom button.

  • Create a custom UIBarButtonItem that suits your requirement.
  • Assign this Custom UIBarButtonItem to the leftBarButtonItem of the NavigationItem.

You can only point to the leftBarButtonItem, since the backBarButtonItem is ReadOnly.

self.navigationItem.leftBarButtonItem = aCustomBarButtonItem;
self.navigationItem.hidesBackButton = YES;

Hope this helps...

EDIT

Code that can help :

UIButton *aCustomButton = [UIButton buttonWithType:UIButtonTypeCustom];
[aCustomButton setBackgroundImage:[UIImage imageNamed:@"back1.png"] forState:UIControlStateNormal];
[aCustomButton setBackgroundImage:[UIImage imageNamed:@"back2.png"] forState:UIControlStateHighlighted];
[aCustomButton addTarget:self action:@selector(onClickOfBack) forControlEvents:UIControlEventTouchUpInside];
[aCustomButton setFrame:CGRectMake(0, 0, 50, 40)];

UIBarButtonItem *aCustomBarButton = [[UIBarButtonItem alloc] initWithCustomView:aCustomButton];
self.navigationItem.leftBarButtonItem = aCustomBarButton;
[aCustomBarButton release];
Roshit
  • 1,589
  • 1
  • 13
  • 37
  • and for the navigation to work correctly, you need to put [self.navigationController popViewControllerAnimated:YES]; in the method 'onClickOfBack' written by @Roshit. – Niko Apr 20 '12 at 07:10