Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw custom Back button on iPhone Navigation Bar

I've got a UIView with a NavigationBar and I'd like to add a button which looks like the style of a Back Button. I'm not using a UINavigationController and was wondering if this could be done without it?

The style of the button should look like this: alt text

Thanks

like image 930
ingh.am Avatar asked Nov 23 '10 19:11

ingh.am


People also ask

How do I get rid of the back button on my Iphone?

Yes, the back button can be disabled. Please navigate to Advanced Website Kiosk Settings–>Navigation–>Disable back button. Kindly enable this restriction to disallow the usage of the back button on the iOS device.


2 Answers

You need to set up a custom stack of UINavigationItem objects and push them on to the UINavigationBar. This is the only way I know of to get a true back button. I haven't tested this code, but you should do something like this:

UINavigationItem *previousItem =
    [[[UINavigationItem alloc] initWithTitle:@"Back title"] autorelease];

UINavigationItem *currentItem =
    [[[UINavigationItem alloc] initWithTitle:@"Main Title"] autorelease];

[navigationBar setItems:[NSArray arrayWithObjects:previousItem, currentItem, nil]
               animated:YES];

To handle when the buttons are pressed you should set yourself as the navigation bar's delegate and implement the UINavigationBarDelegate delegates.

like image 133
Mike Weller Avatar answered Oct 03 '22 00:10

Mike Weller


You can also update this by modifying the backBarButtonItem on the previous view controller (not the currently viewed one).

like image 36
Greg Martin Avatar answered Oct 03 '22 00:10

Greg Martin