Draw custom Back button on iPhone Navigation Bar(在 iPhone 导航栏上绘制自定义后退按钮)
问题描述
我有一个带有 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 导航栏上绘制自定义后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 iPhone 导航栏上绘制自定义后退按钮


- UITextView 内容插图 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- URL编码Swift iOS 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- GPS状态的广播接收器? 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01