导航栏上的自定义后退按钮 [英] Custom back button on navigation bar

查看:117
本文介绍了导航栏上的自定义后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,有许多 UIViewControllers ,带有 UINavigationControllers UINavigationBar 上必须有一个后退按钮和一个主页 UIButton 。所有这一切都很好。

In my application there are many UIViewControllers with UINavigationControllers. There must be a "back" button and a "home" UIButton on the UINavigationBar. All of this works fine.

但我的一些 UIViewControllers 有很长的名字,有时候地方太小了离开了。我正在尝试用自定义后退替换后退按钮的原始标签(它显示上一个视图的标题),但无论我尝试过什么都不起作用:

But some of my UIViewControllers have long names, and sometimes there is too small place left for it. I'm trying to replace the original label of the "back" button (it shows the title of the previous view) with a custom "Back", but whatever I tried it didn't work:

// Title didn't change
[self.navigationItem.backBarButtonItem setTitle:@"Back"];

// Action didn't set, no response from button ( button didn't do anything )
[self.navigationItem.leftBarButtonItem
   setAction:self.navigationItem.backBarButtonItem.action];

我需要后退按钮才能有这样的风格: < a href =https://stackoverflow.com/questions/4260238/draw-custom-back-button-on-iphone-navigation-bar>在iPhone导航栏上绘制自定义后退按钮

And I need the "back" button to have a style like in this question: Draw custom Back button on iPhone Navigation Bar

推荐答案

试试这个

UIBarButtonItem *backBarBtnItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(popViewController)];
[self.navigationItem setBackBarButtonItem:backBarBtnItem];

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

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

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