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

self.navigationItem.leftBarButtonItem = self.editButtonItem;

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

OR

像这样的东西?

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

当前回答

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        // Custom initialization
        self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];

    }
    return self; 
}

就像Kyle Begeman所做的那样,在根视图控制器中添加上面的代码。所有子视图控制器都会被应用。此外,在initWithCoder:方法中添加这个,你可以在xib、storyboard或基于代码的方法中应用根视图控制器的样式。

其他回答

我在viewDidLoad中应用了以下代码,它可以工作:

  // this will set the back button title
self.navigationController.navigationBar.topItem.title = @"Test";

 // this line set the back button and default icon color  

//[[self.navigationController.navigationBar.subviews lastObject] setTintColor:[UIColor blackColor]];

this line change the back default icon to your custom icon
[[self.navigationController.navigationBar.subviews lastObject] setTintColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"menuicon"]]];

只是更新我使用矢量图标

你不需要做什么。你可以通过故事板本身来实现同样的效果。

只要到根导航控制器,并给一个空间。记住,返回按钮不是指向你想要的没有标题的控制器,而是指向根导航控制器。

你可以把这个类别放在AppDelegate中。m文件。 移除UINavigation中所有默认后退按钮的文本。只有箭头“<”或设置自定义图像,如果你需要。

objective - c:

...

@end

@implementation UINavigationItem (Extension)

- (UIBarButtonItem *)backBarButtonItem {

    return [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
}

@end

添加新的UIBarButtonItem到左边的UINavigationItem 改变UIBarButtonItem的使用方式 现在,点击UINavigationItem,并从outlets滑动barBackButtonItem到左UIBarButtonItem

检查这个答案

如何更改UINavigationController返回按钮名称?

设置标题文本为字符串,其中有一个空格,如下所示

title = " "

没有足够的声誉来添加评论:)