如何将UINavigation后退按钮更改为图像? [英] How to change UINavigation Back Button to an image?
问题描述
所以我有这些用于自定义导航栏和项目的图像,它们看起来像这样.当前,我已经设置了自定义导航栏,但是我不知道如何将默认的后退"按钮更改为下方的返回按钮图片,这是我想知道的吗?任何帮助将不胜感激.注意:我正在使用情节提要.谢谢
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 my back button that i don't know how to imlpement.
推荐答案
如果要向UINavigation添加返回按钮,请尝试以下操作:
首先创建后退按钮:
1.如果您不需要后退动作,请执行以下操作:
UIBarButtonItem *myBackButton = [[UIBarButtonItem alloc] initWithTitle:@"Back"
style:UIBarButtonItemStyleDone target:nil action:nil];
2.如果要创建带有图像的后退按钮,请尝试以下操作:
UIBarButtonItem *myBackButton = [[UIBarButtonItem alloc] initWithImage:[UIImage
imageNamed:@"yourImageName"] style:UIBarButtonItemStylePlain target:nil
action:nil]
3.如果要创建带有图像和操作的后退按钮,请尝试以下操作:
UIBarButtonItem *myBackButton = [[UIBarButtonItem alloc] initWithImage:[UIImage
imageNamed:@"yourImageName"] style:UIBarButtonItemStylePlain target:self
action:@selector(goBack:)]
- (void)goBack:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
创建后退按钮后,将其添加到NavigationBar:
self.navigationItem.backBarButtonItem = myBackButton;
添加可以在viewDidLoad方法中实现的后退按钮代码:
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.backBarButtonItem = myBackButton;
}
您需要更多信息,请参见: UIBarButtonItem类参考
And you need more information see this: UIBarButtonItem Class Reference
给您更多示例:
- How to Customize Navigation Bar and Back Button
- UINavigationController with a Custom Back-Button (Image)
- Custom back button with a Navigation Controller
- how to create back button in navigation bar
- Customize the Back Button of UINavigationItem in the Navigation Bar
- UINavigationBar Back Button with images
这篇关于如何将UINavigation后退按钮更改为图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!