大家都知道,在iOS7之后,苹果的界面风格发生了翻天覆地的变化,也就是扁平化的出现。那么这就有了我们今天这篇小技术贴的存在了。跟以往相比,状态栏(状态栏 就是指的最上面的20像素高的部分 )由以往的万年不变的白色风格变成了现在半透明的了。我们可以修改每个view controller中状态栏的外观。通过UIStatusBarStyle常量可以指定状态栏的内容是暗色或亮色。默认情况下,状态栏的显示是暗色。也就是说,状态栏上的时间、电池指示器和Wi-Fi信号显示为暗色。在这里还要注意的是,状态栏是分前景和背景两部分的。所谓的前景部分指的就是显示电池、时间等部分;背景部分就是现实白色或者图片的背景部分;那么在实际开发过程中,就需要我们根据不同的controller来修改我们的状态栏的风格,那该怎么修改呢?请看如下代码:
方法一
-(UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent; // Light content, for use on dark backgrounds
}
- (BOOL)prefersStatusBarHidden
{
return YES; // 是否隐藏状态栏
}
方法二
(1)在project target的Info.plist中,插入一个新的key,名字为View controller-based status bar appearance,并将其值设置为NO。
![](https://img.haomeiwen.com/i941675/3bff98cd5cbf612e.png)
(2) 接下来使用如下代码进行设置
- (void)initializeStatusBarWithApplication:(UIApplication *)application
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
application.statusBarStyle = UIStatusBarStyleLightContent; // Light content, for use on dark backgrounds
} else {
application.statusBarStyle = UIStatusBarStyleDefault; // Dark content, for use on light backgrounds
}
application.statusBarHidden = NO; // 是否隐藏状态栏
}
最终效果
![](https://img.haomeiwen.com/i941675/7cca4404aeb11a80.png)
网友评论