IOS navigationBar 的颜色修改

2017-05-31  本文已影响147人  熊大加油
  1. 修改navigationBar 字体颜色

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];

  1. 修改系统返回按钮,字体颜色大小
    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)里面重置导航颜色

上一篇下一篇

猜你喜欢

热点阅读