为了方便演示,我用storyBoard建立了一个基本的导航栏 并在代码中获得了NavgationBar
1
|
UINavigationBar *bar = self.navigationController.navigationBar;
|
1
|
|
<喎�"http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+PC9wPgo8cD4KyejWw7W8ur3AuLC0xaXR1cmrPC9wPgo8cD48cHJlIGNsYXNzPQ=="brush:java;">[bar setTintColor:[UIColor whiteColor]];
设置导航栏Title颜色
1
2
3
|
[bar setTitleTextAttributes:@{
NSForegroundColorAttributeName :[UIColor whiteColor]
}];
|
设置UINavigationBar背景图片
1
|
[bar setBackgroundImage:[UIImage imageNamed:@
"bg.png"
] forBarMetrics:UIBarMetricsDefault];
|
1
|
|
![\](http://www.2cto.com/uploadfile/Collfiles/20141208/2014120808450529.png)
设置UINavigationBar全透明, 此处随便设置一张图片即可,重要的是BarMetrics属性决定了bar的样式
1
|
[bar setBackgroundImage:[UIImage imageNamed:@
"bg.png"
] forBarMetrics:UIBarMetricsCompact];
|
1
|
|
![\](http://www.2cto.com/uploadfile/Collfiles/20141208/2014120808450530.png)
设置导航栏下方不显示内容,此时导航栏无透明度
1
|
self.extendedLayoutIncludesOpaqueBars = YES;
|
1
|
|
![\](http://www.2cto.com/uploadfile/Collfiles/20141208/2014120808450632.png)
完成之后就是这样了,但是bar的tintColor会成为下方内容的颜色。
![](http://www.2cto.com/uploadfile/Collfiles/20141208/2014120808450733.png)
automaticallyAdjustsScrollViewInsets属性可以控制滚动内容是否会在bar下方显示。