我如何自定义导航返回按钮在iOS 7及以上没有标题?(即只使用箭头)

self.navigationItem.leftBarButtonItem = self.editButtonItem;

我只是想知道它们是否有self。backbuttonitem;

OR

像这样的东西?

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
                   initWithBarButtonSystemItem:UIBarButtonSystemItemBACK 
                   target:self action:@selector(back)];

当前回答

这是有效的,但它会删除前一项的标题,即使你弹出回到它:

self.navigationController.navigationBar.topItem.title = @"";

只需要在推送视图控制器的viewDidLoad上设置这个属性。

其他回答

只用一张图片!

OBJ - c:

- (void)viewDidLoad {
     [super viewDidLoad];
     UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Icon-Back"]
                                                                                        style:UIBarButtonItemStylePlain
                                                                                       target:self.navigationController
                                                                                       action:@selector(popViewControllerAnimated:)];
     self.navigationItem.leftBarButtonItem = backButton;
}

斯威夫特4:

let backBTN = UIBarButtonItem(image: UIImage(named: "Back"), 
                              style: .plain, 
                              target: navigationController, 
                              action: #selector(UINavigationController.popViewController(animated:)))
navigationItem.leftBarButtonItem = backBTN
navigationController?.interactivePopGestureRecognizer?.delegate = self

Icon-Back.png

Icon-Back@2x.png

Icon-Back@3x.png

为你的根视图控制器创建一个带有标题的UILabel,并将它分配给视图控制器的navigationItem.titleView。

现在将标题设置为空字符串,你按下一个视图控制器将有一个没有文本的返回按钮。

self.navigationItem.titleView = titleLabel; //Assuming you've created titleLabel above
self.title = @"";

将标题设置为空

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@""  style:UIBarButtonItemStyleDone target:self action:@selector(handleBack:)];
[backButton setTintColor:Color_WHITE];
[self.navigationItem setBackBarButtonItem:backButton];

换回图像

 UIImage *backImg = [[UIImage imageNamed:@"ic_back_white"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[UINavigationBar appearance].backIndicatorImage = backImg;
[UINavigationBar appearance].backIndicatorTransitionMaskImage = backImg;

唯一对我有效的方法是:

navigationController?.navigationBar.backItem?.title = ""

更新:

当我改变segue动画标志为真(之前是假的),唯一适合我的方法是:

navigationController?.navigationBar.topItem?.title = ""

其实很简单,我是这么做的:

Objective - 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];

斯威夫特2

self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)

斯威夫特3

self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)

把这一行放到推送到堆栈(前一个视图控制器)的视图控制器中。新按下的视图控制器返回按钮现在将显示你为initWithTitle所放的任何东西,在本例中是一个空字符串。