我有一个带有 NavigationBar 的 UIView,我想添加一个看起来像后退按钮样式的按钮.我没有使用 UINavigationController 并且想知道如果没有它是否可以完成?
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:
谢谢
您需要设置一个自定义堆栈的 UINavigationItem
对象并将它们推送到 UINavigationBar.这是我所知道的获得真正后退按钮的唯一方法.我没有测试过这段代码,但你应该这样做:
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];
要在按下按钮时进行处理,您应该将自己设置为导航栏的委托并实现 UINavigationBarDelegate 委托.
To handle when the buttons are pressed you should set yourself as the navigation bar's delegate and implement the UINavigationBarDelegate delegates.
这篇关于在 iPhone 导航栏上绘制自定义后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!