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

查看:35
本文介绍了没有标题的 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天全站免登陆