In my app, i'm using a custom UINavigationBar and custom UIBarButtonItems in a NavigationController. My (custom) NavigationBar looks fine, but when I want to place my own backBarButtonItem and RightBarButtonItem, it goes wrong.
Installing my own backBarButtonItem doesn't work at all (after a PushViewController method). I use this code:
UIButton *home = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *homeImage = [UIImage imageNamed:@"Topbarback"];
[home setBackgroundImage:homeImage forState:UIControlStateNormal];
home.frame = CGRectMake(0, 0, 51, 30);
UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
initWithCustomView:home];
[self.navigationItem setBackBarButtonItem:backButton];
I also have my own rightBarButtonItem. I am able to get it on my NavigationBar, but it isn't calling the method I want to do it. Here's my code for that one:
UIButton *home = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *homeImage = [UIImage imageNamed:@"Topbarback"];
[home setBackgroundImage:homeImage forState:UIControlStateNormal];
home.frame = CGRectMake(0, 0, 51, 30);
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc]
initWithCustomView:home];
// self.navigationItem.backBarButtonItem = cancelButton;
[self.navigationItem setBackBarButtonItem:cancelButton];
After a couple of hours looking on the internet for a solution with no result, I hope that you guys can help me!
Thanks!
EDIT: Sorry posted the wrong code for the last issue:
UIButton *home2 = [UIButton buttonWithType:UIButtonTypeCustom];
[home2 setTitle:@"Sort" forState:UIControlStateNormal];
[home2.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:15]];
UIImage *homeImage2 = [UIImage imageNamed:@"Topbarbutton"];
[home2 setBackgroundImage:homeImage2 forState:UIControlStateNormal];
home2.frame = CGRectMake(0, 0, 77, 30);
UIBarButtonItem *cancelButton2 = [[UIBarButtonItem alloc]
initWithCustomView:home2];
[cancelButton2 setTarget:self];
[cancelButton2 setAction:@selector(sorteren)];
self.navigationItem.rightBarButtonItem = cancelButton2;