设置导航栏的返回按钮以及文字
1、新建一个类(MPSNavigationController)继承至 UINavigationController。
2、
- (void)viewDidLoad {
[super viewDidLoad];
[self configTitleTextStyle];
self.view.backgroundColor = [UIColor whiteColor];//背景色
if ([self.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics: )]) {//设置返回按钮样式。这里是自定义的图片
UIImage *image = [UIImage imageNamed:@"icon_back"];
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
self.navigationBar.backIndicatorImage = image;
self.navigationBar.backIndicatorTransitionMaskImage = image;
}
}
/**
* 设置导航上的title显示样式,白色文字
*/
-(void)configTitleTextStyle{
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
shadow.shadowOffset = CGSizeMake(0, 0);
UIColor *textColor = [UIColor blackColor];
[self.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
textColor, NSForegroundColorAttributeName,shadow, NSShadowAttributeName,[UIFont fontWithName:@"PingFang SC" size:18.0f], NSFontAttributeName,
nil]];
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated//判断如果不是根控制器的话退出的界面自动隐藏底部tabbar
{
if (self.childViewControllers.count) { // 不是根控制器
viewController.hidesBottomBarWhenPushed = YES;
}
[super pushViewController:viewController animated:animated];
}欢迎