有没有办法将所有导航栏后退按钮的标题全局更改为“返回”按钮。 [英] Is there a way to globally change title of all navigtion bar back button to "Back"

查看:80
本文介绍了有没有办法将所有导航栏后退按钮的标题全局更改为“返回”按钮。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在所有视图控制器中更改它是单调乏味的

It's tedious to change it in all view controller

我可以全局更改吗?

推荐答案

您可以使用的是一个类别:

What you can use is a category:

UINavigationItem + MyBackButton.h

UINavigationItem+MyBackButton.h

@interface UINavigationItem (MyBackButton)

@end

UINavigationItem + MyBackButton.m

UINavigationItem+MyBackButton.m

#import "UINavigationItem+MyBackButton.h"

@implementation UINavigationItem (MyBackButton)

-(UIBarButtonItem*)backBarButtonItem
{
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] 
                                   initWithTitle: @"Back Button Text" 
                                   style: UIBarButtonItemStyleBordered
                                   target: nil action: nil];

    return [backButton autorelease];
}
@end

将这两个文件添加到项目中,你就是完成。
为了提高效率,应在此添加ivar和延迟加载。

Add this two files to the project and you are done. To be more efficient ivar and lazy loading should be added here.

这篇关于有没有办法将所有导航栏后退按钮的标题全局更改为“返回”按钮。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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