为了方便演示,我用storyBoard建立了一个基本的导航栏 并在代码中获得了NavgationBar
UINavigationBar *bar = self.navigationController.navigationBar;
设置导航栏按钮颜色
[bar setTintColor:[UIColor whiteColor]];
设置导航栏Title颜色
[bar setTitleTextAttributes:@{ NSForegroundColorAttributeName :[UIColor whiteColor] }];如果需要设置返回按钮的颜色,设置bar的tintColor即可
设置UINavigationBar背景图片
[bar setBackgroundImage:[UIImage imageNamed:@"bg.png"] forBarMetrics:UIBarMetricsDefault];

设置UINavigationBar全透明, 此处随便设置一张图片即可,重要的是BarMetrics属性决定了bar的样式
[bar setBackgroundImage:[UIImage imageNamed:@"bg.png"] forBarMetrics:UIBarMetricsCompact];

设置导航栏下方不显示内容,此时导航栏无透明度
self.extendedLayoutIncludesOpaqueBars = YES;
使用storyBoard需要在控制器中设置

完成之后就是这样了,但是bar的tintColor会成为下方内容的颜色。

automaticallyAdjustsScrollViewInsets属性可以控制滚动内容是否会在bar下方显示。