xcode 如何将 UINavigation 后退按钮更改为图像?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16240168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change UINavigation Back Button to an image?
提问by Robert Saunders
So I have these images that are used for a custom Nav bar and items, they look like this.Currently I have the custom nav bar set up, however I don't know how change the default "back" button to the back button image below, this is what I want to know? Any help would be greatly appreciated. Note: I am using storyboards. Thanks
所以我有这些用于自定义导航栏和项目的图像,它们看起来像这样。目前我设置了自定义导航栏,但是我不知道如何将默认的“后退”按钮更改为后退按钮图像下面,这就是我想知道的?任何帮助将不胜感激。注意:我正在使用故事板。谢谢
This is the nav bar:
这是导航栏:
This is my back button that i don't know how to imlpement.
这是我的后退按钮,我不知道如何实现。
回答by mr.boyfox
If you want add back button to UINavigation try this:
如果您想向 UINavigation 添加后退按钮,请尝试以下操作:
First create back button:
首先创建返回按钮:
1. If you don`t need back action:
1.如果你不需要回动作:
UIBarButtonItem *myBackButton = [[UIBarButtonItem alloc] initWithTitle:@"Back"
style:UIBarButtonItemStyleDone target:nil action:nil];
2. If you want create back button with image try this:
2.如果你想用图像创建后退按钮试试这个:
UIBarButtonItem *myBackButton = [[UIBarButtonItem alloc] initWithImage:[UIImage
imageNamed:@"yourImageName"] style:UIBarButtonItemStylePlain target:nil
action:nil]
3. If you want create back button with image and action try this:
3. 如果你想创建带有图像和动作的后退按钮,试试这个:
UIBarButtonItem *myBackButton = [[UIBarButtonItem alloc] initWithImage:[UIImage
imageNamed:@"yourImageName"] style:UIBarButtonItemStylePlain target:self
action:@selector(goBack:)]
- (void)goBack:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
After created back button add its to NavigationBar:
创建后退按钮后,将其添加到 NavigationBar:
self.navigationItem.backBarButtonItem = myBackButton;
Add back button code you can implement in viewDidLoad method:
添加您可以在 viewDidLoad 方法中实现的后退按钮代码:
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.backBarButtonItem = myBackButton;
}
And you need more information see this: UIBarButtonItem Class Reference
您需要更多信息,请参阅:UIBarButtonItem Class Reference
Here more examples to you:
这里有更多例子给你:
- How to Customize Navigation Bar and Back Button
- UINavigationController with a Custom Back-Button (Image)
- Custom back button with a Navigation Controller
回答by art-divin
Here is how you can do this:
以下是您可以如何执行此操作:
UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStyleBordered target:target action:action;]
self.navigationItem.rightButtonItem = back;
For more info about UIBarButtonItem, go here.
有关 UIBarButtonItem 的更多信息,请转到此处。
Also try to search next time for similar questionsbefore posting new.