没有标题的UINavigationBar自定义后退按钮 [英] UINavigationBar custom back button without title

查看:153
本文介绍了没有标题的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.

这篇关于没有标题的UINavigationBar自定义后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆