設定UINavigationController的返回按鈕 樣式
設定導航欄的返回按鈕以及文字
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];
}歡迎