在 iPhone 导航栏上绘制自定义后退按钮 [英] Draw custom Back button on iPhone Navigation Bar

查看:24
本文介绍了在 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 导航栏上绘制自定义后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆