iOS设置UINavigationBar 的样式

为了方便演示,我用storyBoard建立了一个基本的导航栏 并在代码中获得了NavgationBar

 

	
UINavigationBar *bar = self.navigationController.navigationBar;

 

1
 

 

\

 

[bar setTintColor:[UIColor whiteColor]];

 

设置导航栏Title颜色

 

1
2
3
[
bar setTitleTextAttributes:@{
                                  NSForegroundColorAttributeName :[UIColor whiteColor]
                                  }];

 

如果需要设置返回按钮的颜色,设置bar的tintColor即可

 


\

 

 

 

设置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
 
使用storyBoard需要在控制器中设置

 

 

\

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

 

 

同时在滚动视图中 设置

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

 

 

 
posted @ 2015-07-21 10:28  孤光一点莹  阅读(374)  评论(0编辑  收藏  举报