为了方便演示,我用storyBoard建立了一个基本的导航栏 并在代码中获得了NavgationBar
UINavigationBar *bar = self.navigationController.navigationBar;
|
1
|
|
[bar setTintColor:[UIColor whiteColor]];
设置导航栏Title颜色
|
1
2
3
|
bar setTitleTextAttributes:@{
NSForegroundColorAttributeName :[UIColor whiteColor]
}];
|
设置UINavigationBar背景图片
|
1
|
[bar setBackgroundImage:[UIImage imageNamed:@"bg.png"] forBarMetrics:UIBarMetricsDefault];
|
|
1
|
|
设置UINavigationBar全透明, 此处随便设置一张图片即可,重要的是BarMetrics属性决定了bar的样式
|
1
|
[bar setBackgroundImage:[UIImage imageNamed:@"bg.png"] forBarMetrics:UIBarMetricsCompact];
|
|
1
|
|
设置导航栏下方不显示内容,此时导航栏无透明度
|
1
|
self.extendedLayoutIncludesOpaqueBars = YES; |
|
1
|
|
完成之后就是这样了,但是bar的tintColor会成为下方内容的颜色。
同时在滚动视图中 设置
automaticallyAdjustsScrollViewInsets属性可以控制滚动内容是否会在bar下方显示。