本文主要是介绍iOS 设置状态栏,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
解决方案是
添加
View controller-based status bar appearance = NO; 必须是这个
然后再 AppDelegate.cpp
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
添加一行
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
可是就算这样放置,也是有问题的 白字出来了,黑底还是没有出来。
因为我是自定义的navigationbar,所以才用了下图的第二种解决方案:
以下是我的实现代码:
UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, -DeviceStatusBarHeight, SCREEN_WIDTH, DeviceStatusBarHeight)];
view.backgroundColor = [UIColor blackColor];
[self.navigationController setNavigationBarHidden:YES];
UINavigationBar * bar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0,DeviceStatusBarHeight, SCREEN_WIDTH, 44)];
[bar setBackgroundImage:[UIImage imageNamed:@"绿色条.png"] forBarMetrics:UIBarMetricsDefault];
[bar addSubview:view];
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 44)];
label.backgroundColor = [UIColor clearColor];
label.text = @"通讯录";
label.textColor = [UIColor whiteColor];
label.textAlignment = NSTextAlignmentCenter;
UINavigationItem * item = [[UINavigationItem alloc]init];
[item setTitleView:label];
[bar pushNavigationItem:item animated:YES];
[self.view addSubview:bar];
这篇关于iOS 设置状态栏的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!