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

.

enter image description here

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


short answer: you cannot do this.



you can save the image and you can put the image in that position, but the back button is driven by the private part UINavigationBar

.

+3


source


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


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


This works for me: [self.navigationItem.leftBarButtonItem setTitle:@"Back"];

(custom text with back arrow)

0


source







All Articles