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];