Create UIBarButtonItem with a back button
I'm looking for a way to create programmatically UIBarButtonItem
that looks like a back button UINavigationBar
. Apparently it looks like the back button only appears after the button is pressed UINavigationController
.
So, I can only insert a button with an "undo" style. But my goal is to create a button with the New Item style.
Ideas?
+3
source to share
4 answers
I think you need to use an image. and then set the image as the buttons backgroundImage. eg:
navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
UINavigationItem *navigationItem = [[[UINavigationItem alloc] initWithTitle:@"Detail"] autorelease];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 70, 30)];
[button setImage:[UIImage imageNamed:@"plain.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonClicked:)
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc]
initWithCustomView:button];
navigationItem.leftBarButtonItem = buttonItem;
[buttonItem release];
[button release];
[navigationBar pushNavigationItem:navigationItem animated:NO];
[self.view addSubview:navigationBar];
+1
source to share
Take a look at this answer: Creating a left arrow button (like UINavigationBar style ") on a UIToolbar
It gives you the psd file with the image you want.
0
source to share