![](/img/trans.png)
[英]MFMailComposeViewController in iOS 7 statusbar are black
[英]iOS 8 make statusbar black and not translucent
因此,我的应用程序中的状态栏当前如下所示:
我希望它看起来像这样:
2 http://mojoimage.com/free-image-hosting-12/22iOS7_StatusBar-copy.png
因此它是黑色的,带有白色文本。 目前,由于背景不是黑色,因此无法在该特定屏幕上使用。 而且我已经将pList中的Status Bar Style
UIStatusBarStyleLightContent
为UIStatusBarStyleLightContent
。
我还要添加一个视图,它是初始的ViewController,并且没有嵌入UINavigationController
:
编辑:这不是重复的,因为大多数其他以前的解决方案已经过时了。
您可以将其设置为亮,然后在其后面抛一个视图。 如果您在应用中允许设备旋转,则还必须考虑设备旋转。
迅速:
override func viewDidLoad() {
super.viewDidLoad()
let statusBG = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 21))
statusBG.backgroundColor = UIColor.blackColor()
view.addSubview(statusBG)
}
目标C:
- (void)viewDidLoad {
[super viewDidLoad];
UIView *statusBG = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 21)];
statusBG.backgroundColor = [UIColor blackColor];
[self.view addSubview:statusBG];
}
因为在iOS 6或更早版本上,状态栏不是半透明的,所以最好基于iOS版本执行此操作。 在您的viewDidLoad
:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
UIView *statusBarView=[[UIView alloc] initWithFrame:CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, 20)];
statusBarView.backgroundColor=[UIColor blackColor];
[self.view addSubview:statusBarView];
}
其中SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO
:
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
这将为您提供带有黑色背景和白色文本的状态栏。
在您的AppDelegate applicationDidFininshLaunchingWithOptions方法中编写以下代码。这有助于您的所有视图控制器。您无需在每个视图控制器中添加代码。
[UIApplication sharedApplication].statusBarHidden=NO;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
[application setStatusBarHidden:NO];
self.window.clipsToBounds=YES;
self.window.frame = CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
}
else
{
self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
[application setStatusBarHidden:NO];
self.window.clipsToBounds=YES;
self.window.frame = CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
}
然后你yourprojectName.plist给
Status bar is initially hidden is NO
View controller-based status bar appearance is YES
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.