iOS 更改导航栏背景颜色

2019-05-23  本文已影响0人  zxb有缘

//1.设置导航栏透明,贴出关键代码
self.view.backgroundColor = [UIColor yellowColor];
self.navigationItem.title = @"这是一个Title";

//设置导航栏背景图片为一个空的image,这样就透明了
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
//去掉透明后导航栏下边的黑边
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
self.navigationController.navigationBar.translucent = YES;

//2.设置title的字体以及颜色,关键代码如下所示:
self.view.backgroundColor = [UIColor yellowColor];
self.navigationItem.title = @"这是一个Title";

//设置导航栏背景图片为一个空的image,这样就透明了
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
//去掉透明后导航栏下边的黑边
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
self.navigationController.navigationBar.translucent = YES;

[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor redColor],
                                                                  NSFontAttributeName : [UIFont fontWithName:@"Helvetica-Bold" size:16]}];
上一篇 下一篇

猜你喜欢

热点阅读