这是我在AppDelegate类(Swift 4)中编写的代码:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
UIApplication.shared.statusBarStyle = .lightContent
goToRootViewController()
UINavigationBar.appearance().isTranslucent = true
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
GMSServices.provideAPIKey(googleMapApiKey)
return true
}
但是我的状态栏没有显示轻量级内容我不知道什么是ging,任何帮助?
答案 0 :(得分:11)
在viewcontroller类中,使用viewDidLoad()下面的代码:
override var preferredStatusBarStyle : UIStatusBarStyle {
return .lightContent
}
这将在轻量级内容中显示您的状态栏
设置"查看基于控制器的状态栏外观"有价值的关键"否"在您产品的Info.plist
中然后在AppDelegate.Swift里面使用以下代码" didFinishLaunchingWithOptions":
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
UIApplication.shared.statusBarStyle = .lightContent
return true
}
答案 1 :(得分:1)
答案 2 :(得分:0)
您是否在info.plist中更改查看基于控制器的状态栏外观行并将其设置为NO? 因为这是更改状态栏外观所必需的
如果您只想更改特定视图控制器上的状态栏,则可以使用
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
答案 3 :(得分:0)
在特定控制器的didLoad中使用以下代码
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
statusBar.backgroundColor = [self colorWithHexString:@"C2BFAB"];//set whatever color you like
// appDel.statusBarColor = NO;
}
答案 4 :(得分:0)
“ statusBarStyle”的设置在iOS 9.0中已被弃用:使用-[UIViewController preferredStatusBarStyle]
在AppDelegate函数UIApplication.shared.statusBarStyle = .lightContent
下手动设置-didFinishLaunchingWithOptions
似乎无效
首先在文件Info.plist
中设置
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
第二:
Target -> General -> Deployment Info
将Status Bar Style
设置为Light