如何将图像设置为 UINavigationController 的后退按钮

发布于 2024-09-11 12:30:08 字数 44 浏览 2 评论 0原文

我想将图像设置为 UINavigationController 的后退按钮

I want to set an image to the back button of UINavigationController

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

默嘫て 2024-09-18 12:30:08

使用此代码:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0,0,36,30);
[button setBackgroundImage:[UIImage imageNamed:@"backgroundImage.png"] forState:UIControlStateNormal];

[button addTarget:self.navigationController action:@selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
[self.navigationItem setLeftBarButtonItem:barButtonItem];

或使用此库。非常简单且美观的结果。

https://github.com/boctor/idev-recipes/tree/master/自定义后退按钮

Use this code:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0,0,36,30);
[button setBackgroundImage:[UIImage imageNamed:@"backgroundImage.png"] forState:UIControlStateNormal];

[button addTarget:self.navigationController action:@selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
[self.navigationItem setLeftBarButtonItem:barButtonItem];

Or use this library. Very easy and good looking result.

https://github.com/boctor/idev-recipes/tree/master/CustomBackButton

睡美人的小仙女 2024-09-18 12:30:08

您无法更改默认后退按钮,因为它不允许您覆盖它。相反,您必须使用 leftBarButtonItem 创建自定义“后退”按钮。

更多信息请参见:

一些之前的代码可供参考: UINavigation 控制器按钮,如 backButton

You cannot change the default back button since it will not let you override it. Instead you have to use the leftBarButtonItem to create a custom "back" button.

More information here: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UINavigationController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006934-CH3-SW25

Some prior code to reference: UINavigation controller button like backButton

毁梦 2024-09-18 12:30:08

只需在导航控制器上调用 popViewControllerAnimated 即可返回。

Just call popViewControllerAnimated on the navigation controller and it will go back.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文