UINavigationBar样式修改代码片段
2020-07-29 本文已影响0人
hypercode
A(第一种). [[UINavigationBar appearance] setBackgroundImage:[UIImage imageWithColor:[UIColor redColor]] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[UIImage new]];
B(第二种).
[self.navigationController.navigationBar setTintColor:[UIColor redColor]];
[self.navigationController.navigationBar setBarTintColor:[UIColor redColor]];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:[UIColor redColor]] forBarMetrics:UIBarMetricsDefault];
修改系统返回按钮,字体颜色大小
UIImage *backButtonImage = [UIImage imageNamed:@"back"];
[[UINavigationBar appearance] setBackIndicatorImage:backButtonImage];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:backButtonImage];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:MZFontNavigationTitleFontSize]}];
在ios10中,如果需要对单个页面修改颜色,在viewWilldisapper里面重置无效[但是手势返回有效,返回按钮返回颜色会有明显变化],这个时候需要在navigationcontroller的方法popviewcontrollerxxx(或者pushviewcontroller)里面重置导航颜色