我的应用程序背景是黑色的,但在iOS 7中,状态栏变成了透明的。所以我什么也看不见,只有角落里的绿色电池指示灯。如何将状态栏文本颜色改为白色,就像在主屏幕上一样?
当前回答
如果你有一个通过Interface Builder创建的嵌入式导航控制器,请确保在管理导航控制器的类中设置以下内容:
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
这应该就是你所需要的。
其他回答
如果你的UIViewController在UINavigationController中,你必须设置BarStyle:
-[UINavigationBar setBarStyle:UIBarStyleBlack]
原始答案在这里
https://devforums.apple.com/message/844264#844264
如果你想用Swift得到同样的结果,你可以在你的AppDelegate.swift文件中使用下面的代码:
UINavigationBar.appearance().barStyle = .BlackTranslucent
你的状态栏的文本将是白色的:-)!
只需以下两步:
步骤1:
在项目目标的Info选项卡下,添加行:
UIViewControllerBasedStatusBarAppearance,设置值NO。
步骤2:
在项目AppDelegate.m中:
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
…
[application setStatusBarStyle:UIStatusBarStyleLightContent];
…
}
请试试这个
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
[application setStatusBarHidden:NO];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
statusBar.backgroundColor = [UIColor blackColor];
}
如果你想将它设置为任何颜色,请使用下面的代码。
id statusBarWindow = [[UIApplication sharedApplication] valueForKey:@"statusBarWindow"];
id statusBar = [statusBarWindow valueForKey:@"statusBar"];
SEL setForegroundColor_sel = NSSelectorFromString(@"setForegroundColor:");
if([statusBar respondsToSelector:setForegroundColor_sel]) {
// iOS 7+
[statusBar performSelector:setForegroundColor_sel withObject:YourColorHere];
^^^^^^^^^^^^^
}
我知道我正在访问私有API,但我已经在许多项目中使用了这个,苹果已经批准了它。
在提交应用程序时,将此代码发送到Apple的评论部分,并告知您正在使用此代码更改状态栏的颜色。
是的,不要忘记下面的内容。
推荐文章
- 如何删除默认的导航栏空间在SwiftUI导航视图
- Ios模拟器:如何关闭应用程序
- 如何在iOS中使用Swift编程segue
- Swift -整数转换为小时/分钟/秒
- 如何舍入一个双到最近的Int在迅速?
- 扁平化数组的数组在Swift
- Swift:声明一个空字典
- 在成功提交我的应用程序后,“太多符号文件”
- 从数组中随机选择一个元素
- 首先添加一个UIView,甚至是导航栏
- 我如何改变UIButton标题颜色?
- 在Swift中如何调用GCD主线程上的参数方法?
- NSLayoutConstraints是可动画的吗?
- iOS -构建失败,CocoaPods无法找到头文件
- CFNetwork SSLHandshake iOS 9失败