关于UINavigationController

来源:互联网 发布:企业整站源码 编辑:程序博客网 时间:2024/06/07 15:46

如果项目用到视图控制器是UINavigationController,建议继承UINavigationController重写里面的方法。

这样可以保证整个控制器的navigation风格一致,特别是处理自动旋转问题,最好重写UINavigationController的shouldAutorotate方法,以保证UINavigationController每一个视图控制器的旋转效果一致。

重写代码如下:

    UINavigationBar *navBar = [UINavigationBar appearance];    UIBarButtonItem *barItem = [UIBarButtonItem appearance];    [navBar setBackgroundImage:[UIImage imageNamed:@"navigationbar_background.png"] forBarMetrics:UIBarMetricsDefault];    //navBar.barTintColor = [UIColor greenColor];设置bar的背景    navBar.tintColor = [UIColor whiteColor];    [navBar setTitleTextAttributes:@{                                     NSForegroundColorAttributeName : [UIColor whiteColor]                                     }];    [barItem setBackgroundImage:[UIImage imageNamed:@"navigationbar_button_background.png"]     forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];    [barItem setTitleTextAttributes:@{                                      NSForegroundColorAttributeName : [UIColor whiteColor],                                      NSFontAttributeName : [UIFont systemFontOfSize:15]                                    } forState:UIControlStateNormal];    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];


0 0
原创粉丝点击