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

self.navigationItem.leftBarButtonItem = self.editButtonItem;

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

OR

像这样的东西?

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

当前回答

这招对我很管用

[[UIBarButtonItem appearance] 
setBackButtonTitlePositionAdjustment:UIOffsetMake(-1000, -1000) 
forBarMetrics:UIBarMetricsDefault];

愿一切都好!

其他回答

你不能以你想要的方式访问导航backButtonItem,你需要创建自己的返回按钮,如下所示:

- (void)loadView
{
    [super loadView];
    UIButton *backButton = [[UIButton alloc] initWithFrame: CGRectMake(0, 0, 44.0f, 30.0f)];
    [backButton setImage:[UIImage imageNamed:@"back.png"]  forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(popVC) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
}

当然了:

- (void) popVC{
  [self.navigationController popViewControllerAnimated:YES];
}

iOS7有新的界面规则,所以当你推送一个UIView时,最好至少保留后退箭头。 通过编程方式更改“返回”文本非常容易。只需要在推送视图之前添加这段代码(如果你使用的是StoryBoards,可以使用prepareForSegue):

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
      self.navigationItem.backBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"NEW TITLE" style:UIBarButtonItemStylePlain target:nil action:nil];
}

这将改变默认的“后退”文本,但将保持iOS7风格的后退箭头。 你也可以在推送视图之前改变后退箭头的颜色:

- (void)viewDidLoad{
     //NavBar background color:
     self.navigationController.navigationBar.barTintColor=[UIColor redColor];
//NavBar tint color for elements:
     self.navigationController.navigationBar.tintColor=[UIColor whiteColor];
}

希望这对你有所帮助!

你可以子类化UINavigationController,将自己设置为委托,并在委托方法navigationController:willShowViewController:animated中设置backBarButtonItem:

@interface Custom_NavigationController : UINavigationController <UINavigationControllerDelegate>

@end

@implementation Custom_NavigationController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.delegate = self;
}

#pragma mark - UINavigationControllerDelegate

- (void)navigationController:(UINavigationController *)navigationController     willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    viewController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
}

@end

改变backItem。title = "" to使用topItem。标题= "" 设置navigationItem。hidesBackButton = true & navigationItem。leftBarButtonItem将失去后退手势 记住,我们必须创建2个back映像的实例

我的解决方案将改变图像和保持后面的手势:

navigationController?.navigationBar.backIndicatorImage = UIImage(named: "back")
navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "back")
navigationController?.navigationBar.topItem?.title = ""

这在iOS6和ios7上都很有效

Xamarin (c#)选项

var buttonStyleItems = UIBarButtonItem.AppearanceWhenContainedIn(typeof(SettingsNavigationController));
buttonStyleItems.SetBackButtonTitlePositionAdjustment(new UIOffset(-1000, -1000), UIBarMetrics.Default);

objective - c选项

[[UIBarButtonItem外观]setBackButtonTitlePositionAdjustment:UIOffsetMake(-1000, -1000) forBarMetrics:UIBarMetricsDefault];