#import <UIKit/UIKit.h>
@interface BasicNavigationController : UINavigationController
@end
#import "BasicNavigationController.h"
@interface BasicNavigationController ()
@end
@implementation BasicNavigationController
- (void)viewDidLoad {
[super viewDidLoad];
// 1.appearance方法返回一个导航栏的外观对象
// 修改了这个外观对象,相当于修改了整个项目中的外观
UINavigationBar *bar = [UINavigationBar appearance];
// 2.设置导航栏的背景图片
//2.1修改导航栏系统返回箭头图片
bar.backIndicatorImage = [UIImage imageNamed:@"nav_backItem_white"];
bar.backIndicatorTransitionMaskImage = [UIImage imageNamed:@"nav_backItem_white"];
//2.2设置shadowImage
[bar setBarStyle:UIBarStyleBlackTranslucent];
bar.shadowImage = [[UIImage alloc] init];
//2.3设置导航栏颜色
[bar setTintColor:[UIColor whiteColor]];
[bar setBarTintColor:KGlobalBlueColor];
// 3.设置导航栏文字的主题
[bar setTitleTextAttributes:@{
NSFontAttributeName : KFontHeadline,
NSForegroundColorAttributeName : [UIColor whiteColor]
}];
// 4.修改所有UIBarButtonItem的外观
UIBarButtonItem *barItem = [UIBarButtonItem appearance];
//4.1设置返回不需要文字
//注:添加此方法,切换应用会出现一闪
// [barItem setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault];
// 5.修改item上面的文字样式
NSDictionary *dict = @{
NSFontAttributeName: KFontSubhead,
NSForegroundColorAttributeName : [UIColor whiteColor]
};
NSDictionary *dictEnable = @{
NSFontAttributeName: KFontSubhead,
NSForegroundColorAttributeName: KGreyColor,
};
[barItem setTitleTextAttributes:dict forState:UIControlStateNormal];
[barItem setTitleTextAttributes:dict forState:UIControlStateHighlighted];
[barItem setTitleTextAttributes:dictEnable forState:UIControlStateDisabled];
}
@end