状态栏全透明效果

今天想在Demo里设置导航栏全透明效果,并与视图背景颜色相同。查找方法的过程中发现网上的一些方法不是很适用,然后看了下文档,试了一下,发现以下两句代码就可以实现效果。

文档说明:

The default value is nil, which corresponds to the default shadow image. When non-nil, this property represents a custom shadow image to show instead of the default. For a custom shadow image to be shown, a custom background image must also be set with the setBackgroundImage:forBarMetrics: method. If the default background image is used, then the default shadow image will be used regardless of the value of this property.

代码:

[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init]
    forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage: [[UIImage alloc] init]];

设置状态栏样式

顺便记录一下如何设置状态栏样式

1.设置项目Info中项目属性,添加View controller-based status bar appearance,设置为NO

2.设置代码

[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

整体效果图如下: