美文网首页
IOS navigationBar 的颜色修改

IOS navigationBar 的颜色修改

作者: 熊大加油 | 来源:发表于2017-05-31 13:58 被阅读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)里面重置导航颜色

    相关文章

      网友评论

          本文标题:IOS navigationBar 的颜色修改

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