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.
Asked
Active
Viewed 156 times
0
-
So what specifically have you tried? So that others don't repeat. – Luke Apr 19 '12 at 22:46
1 Answers
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];
![](../../users/profiles/942966.webp)
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