iOS导航栏的颜色和电池颜色的修改

一般情况下 我们的导航栏的颜色都是系统设定的,一般都是白色的,而电池的颜色则是黑色的,但是这样一来,如果我们的需求是将导航栏的颜色修改成黑色,那么此时如果我们的电池的颜色还是黑色的,这不就看不清了;

1.修改导航栏的颜色

[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];

我们在AppDelegate里面修改导航栏的颜色,但是这种修改是将全部的导航栏都修改颜色,所以,如果我们的需求是在不同的页面要求导航栏的颜色是不一样的,那么此时我们就应该自定义导航栏了。所谓的自定义就是自己写一个View贴到原来的导航栏上面,那么此时,导航栏的颜色不就是想怎么设置就怎么设置了么

2,我们再来说说,怎么设置导航栏上的电池的颜色。

自定义导航栏上的字体

1.

[self.navigationController.navigationBar setTitleTextAttributes:

@{NSFontAttributeName:[UIFont systemFontOfSize:19],

NSForegroundColorAttributeName:[UIColor redColor]}];

2.自定义

//自定义导航栏上字体
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 44)];
    titleLabel.backgroundColor = [UIColor colorWithRed:20/255.0 green:20/255.0 blue:20/255.0 alpha:1];
    titleLabel.font = [UIFont boldSystemFontOfSize:20];
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = @"Welcome";
    self.navigationItem.titleView = titleLabel;

以上就是简单的导航栏的设置,接下来会有进一步的补充

原文地址:https://www.cnblogs.com/nsjelly/p/4545960.html