开发者

Draw custom Back button on iPhone Navigation Bar

开发者 https://www.devze.com 2023-01-26 08:06 出处:网络
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 th开发者_运维知识库is co

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 th开发者_运维知识库is could be done without it?

The style of the button should look like this:

Draw custom Back button on iPhone Navigation Bar

Thanks


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消