一 . UINavigationBarapp
1.获取 UINavigationBar 对象: [UINavigationBar appearance] ,能够经过该方法对所有 navigation 进行设置字体
2.设置导航栏背景图片:[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"name"] forBarMetrics:UIBarMetricsDefault];spa
3.设置标题字体:[UINavigationBar appearance].titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};code
二 . UIBarButtonItemorm
1.获取 UIBarButtonItem 对象: [UIBarButtonItem appearance] 能够经过该方法实现对 barButtonItem (即导航栏按钮)样式,显示字体进行设置 (同一 navigation 下所有)对象
2.设置按钮的颜色,大小 : [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:13]} forState:UIControlStateNormal];图片
3.设置导航栏渐变色(返回箭头白色) : [UIBarButtonItem appearance].tintColor = [UIColor whiteColor];it
三 . 去除 navigation 下边黑线io
//去掉导航栏黑线 [[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault]; [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
四 . 修改 backItem 为图片class
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:[[UIImage imageNamed:@"common_nav_back"] imageWithAlignmentRectInsets:UIEdgeInsetsMake(0, 0, 0, -15)] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault];
图片进行处理,不然图片会被横向拉伸(imageWithAlignmentRectInsets 设置图片距离边的距离)
五 . 用本身的图片替换V型,能够设置图片的backIndicatorImage
和backIndicatorTransitionMaskImage
。以下代码所示:
[[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:@"back_btn.png"]]; [[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"back_btn.png"]];