Navigation导航设置
为了统一管理导航控制器,需要自定义导航控制器MJNavigationController,继承于UINavigationController。分别设置5个Navigation的控制器Class为此控制器。
- 白色状态栏
- 统一背景头部导航栏
- 设置所有Navigation导航栏字体颜色
- 二级页面隐藏底部导航条
1.白色状态栏。使用application管理状态栏
设置不使用控制器控制状态栏
在MJAppDelegate中设置:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. application.statusBarStyle=UIStatusBarStyleLightContent; return YES; }
这样会导致程序在启动的时候,有显示状态栏,如图
改进:
程序启动期间隐藏状态栏
程序启动完成显示状态栏
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. application.statusBarStyle=UIStatusBarStyleLightContent; //显示导航栏 application.statusBarHidden=NO; return YES; }
2.统一背景头部导航栏,所有Navigation导航栏字体颜色及返回字体按钮颜色
MJNavigationController控制器的类initialize只会在类的第一次调用时使用,因此在这个方法里设置
/*
*
* 系统在第一次使用这个类的时候调用(1个类只会调用一次)
*/
+(void)initialize
{
//设置导航栏背景
UINavigationBar *navBar=[UINavigationBar appearance];
[navBar setBackgroundImage:[UIImage imageNamed:@"NavBar64"] forBarMetrics:UIBarMetricsDefault];
//设置标题文字颜色
NSMutableDictionary *attrs=[NSMutableDictionary dictionary];
attrs[NSForegroundColorAttributeName]=[UIColor whiteColor];
attrs[NSFontAttributeName]=[UIFont systemFontOfSize:16];
[navBar setTitleTextAttributes:attrs];
//设置BarButtonItem的主题
UIBarButtonItem *item=[UIBarButtonItem appearance];
NSMutableDictionary *itemAttrs=[NSMutableDictionary dictionary];
itemAttrs[NSForegroundColorAttributeName]=[UIColor whiteColor];
itemAttrs[NSFontAttributeName]=[UIFont systemFontOfSize:14];
[item setTitleTextAttributes:itemAttrs forState:UIControlStateNormal];
//设置BarButtonItem返回箭头颜色
navBar.tintColor=[UIColor whiteColor];
}
3.二级页面隐藏底部导航条
重写push方法,隐藏底部导航栏
/*
*
* 重写这个方法,拦截所有的push操作
*/
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
viewController.hidesBottomBarWhenPushed=YES;
[super pushViewController:viewController animated:animated];
}
自定义导航栏标题按钮
不能选择UIBarButtonItem,UIBarButtonItem在storyboard中只能选择文字或者图片之一。
(1)选用UIButton,分别设置名称、图片、字体大小
(2)设置内间距及向右对齐
原文:http://www.cnblogs.com/jys509/p/4782240.html
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!