Customize the back button of a navigation controller
I want to have two buttons on the left side of the navigation bar, one is the regular back button and the other one is a UIBarButtonItem. However I could only get it to replace the default back button. I've tried many code samp开发者_运维技巧les on the internet but couldn't get any to work. please help
Don't do this. It breaks the UI guidelines put forth by Apple. See the paragraph right before figure 6-6 of the iPhone HIG.
As far as I'm aware it's not (currently) possible to have two UIBarButtonItems
on either side of a UINavigationBar
.
For this you have to use the UIToolBar for multiple buttons on navigation controller
Yes you can do this by-
UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *homeImage = [UIImage imageNamed:@"YOUR_IMAGE.png"];
[backBtn setBackgroundImage:homeImage forState:UIControlStateNormal];
[backBtn addTarget:self action:@selector(YOUR_ACTION)
forControlEvents:UIControlEventTouchUpInside];
backBtn.frame = CGRectMake(0, 0, 69, 26);
UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
[[self navigationItem] setLeftBarButtonItem:button1];
[button1 release];
button1 = nil;
精彩评论