Swift 设置导航栏的全局返回按钮,去掉文字

来源:互联网 发布:知乎华为mate10 编辑:程序博客网 时间:2024/05/18 00:07

前天为满足UI设计需求,所有导航栏左上角的返回按钮只显示一个三角返回图标,去掉文。

具体实现是,在基类的导航控制器中做如下设置:

#import "CLBaseNavController.h"@interface CLBaseNavController ()@end@implementation CLBaseNavController- (void)viewDidLoad {    [super viewDidLoad];        self.navigationBar.tintColor = [UIColor blackColor];    self.navigationBar.barTintColor = [UIColor whiteColor];    self.navigationBar.alpha = 1.0f;    [self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]}];    self.navigationBar.translucent = NO;        //将返回按钮的文字position设置不在屏幕上显示  NSIntegerMin    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];    [UINavigationBar appearance].backIndicatorTransitionMaskImage = [UIImage imageNamed:@"nav_lift"];    [UINavigationBar appearance].backIndicatorImage = [UIImage imageNamed:@"nav_lift"];    }
其中将返回按钮的文字position设置不在屏幕上显示设置文字便宜量为-60,效果挺好;但是之前的设置是下面这句:

#define NSIntegerMax    LONG_MAX
#define NSIntegerMin    LONG_MIN

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

这样虽然出现了想要的效果,但是引发了另一个不知道算不算bug的bug:

在点击进入导航控器进入第一层时,双击Home键,app在后台显示的是透明的,当偏移量从宏定义的值换成一个固定的数字-60时,透明现象就消失了。

效果达到了,但是现在仍不明白这个偏移值跟双击Home后台app的显示有什么关系......

阅读全文
0 0
原创粉丝点击