没有标题的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.