美文网首页
UINavigationBar样式修改代码片段

UINavigationBar样式修改代码片段

作者: hypercode | 来源:发表于2020-07-29 13:44 被阅读0次
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)里面重置导航颜色

相关文章

网友评论

      本文标题:UINavigationBar样式修改代码片段

      本文链接:https://www.haomeiwen.com/subject/thphrktx.html