没有标题的 UINavigationBar 自定义后退按钮
问题描述:
如何在没有标题的iOS 7及以上版本中自定义导航返回按钮?(即只有箭头)
How can I customize the navigation back button in iOS 7 and above without title? (i.e. with the arrow only)
self.navigationItem.leftBarButtonItem = self.editButtonItem;
我只是想知道他们是否有任何 self.backButtonItem;
I'm just wondering if they have any self.backButtonItem;
或
类似的东西?
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemBACK
target:self action:@selector(back)];
答
其实很简单,我就是这样做的:
It's actually pretty easy, here is what I do:
目标 C
// Set this in every view controller so that the back button displays back instead of the root view controller name
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
Swift 2
self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)
Swift 3
self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
将此行放在推送到堆栈的视图控制器中(前一个视图控制器).新按下的视图控制器后退按钮现在将显示您为 initWithTitle 设置的任何内容,在本例中为空字符串.
Put this line in the view controller that is pushing on to the stack (the previous view controller). The newly pushed view controller back button will now show whatever you put for initWithTitle, which in this case is an empty string.