SwiftUI:状态栏颜色 [英] SwiftUI: Status bar color

查看:358
本文介绍了SwiftUI:状态栏颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将SwiftUI视图的状态栏更改为白色?

Is there a way to change the status bar to white for a SwiftUI view?

我可能缺少一些简单的东西,但似乎找不到在SwiftUI中将状态栏更改为白色的方法.到目前为止,我只看到.statusBar(hidden: Bool).

I'm probably missing something simple, but I can't seem to find a way to change the status bar to white in SwiftUI. So far I just see .statusBar(hidden: Bool).

推荐答案

与链接的评论一样,我编辑了

As in the comments linked to I edited this question here

但是要回答这个问题并帮助人们直接找到答案:

But to answer this question and help people find the answer directly:

Swift 5和SwiftUI

Swift 5 and SwiftUI

为SwiftUI创建一个名为HostingController.swift的新swift文件

For SwiftUI create a new swift file called HostingController.swift

import SwiftUI

class HostingController<ContentView>: UIHostingController<ContentView> where ContentView : View {
    override var preferredStatusBarStyle: UIStatusBarStyle {
        return .lightContent
    }
}

然后在SceneDelegate.swift中更改以下代码行

Then change the following lines of code in the SceneDelegate.swift

window.rootViewController = UIHostingController(rootView: ContentView())

window.rootViewController = HostingController(rootView: ContentView())

这篇关于SwiftUI:状态栏颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆