iphone - 用于后退按钮的自定义UIBarButtonItem [英] iphone - Custom UIBarButtonItem for back button

查看:84
本文介绍了iphone - 用于后退按钮的自定义UIBarButtonItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在导航栏中使用自定义项目作为后退按钮。

I am trying to use a custom item for the back button in my navigation bar.

UIImage *backButtonImage = [UIImage imageNamed:@"backbutton.png"];
UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithImage:backButtonImage style:UIBarButtonItemStylePlain target:nil action:nil];
[self.navigationItem setBackBarButtonItem: customItem];
[customItem release];

我最终得到的是带有边框的图像。它看起来像这样(我的图像是后退按钮):

What I end up getting is my image with a border around it. It looks like this (My image is the back button):

如何摆脱边界?我做错了什么?

How can I get rid of the border? What am I doing wrong?

推荐答案

您的图片出现在后退按钮内部,显然(从您的屏幕截图中)没有与后退按钮大小相同。

Your image is appearing inside of a back button and it is apparently (from your screenshot) not the same size as the back button.

您可能想要隐藏后退按钮,然后将其替换为左栏按钮。

You might want to hide the back button and then replace it with a "Left Bar Button" instead.

代码:

UIImage *backButtonImage = [UIImage imageNamed:@"backbutton.png"];
UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithImage:backButtonImage style:UIBarButtonItemStylePlain target:self.navigationController action:@selector(popViewControllerAnimated:)];
[self.navigationController setHidesBackButton:YES];
[self.navigationItem setLeftBarButtonItem: customItem];
[customItem release];

这篇关于iphone - 用于后退按钮的自定义UIBarButtonItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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