ios 13导航栏和状态栏不透明

时间:2020-02-20 17:38:54

标签: ios uinavigationbar swiftui

我试图在swiftui中实现自己的导航视图。但是状态看起来不像导航栏一样透明。

enter image description here

使用.edgesIgnoringSafeArea(.top),它按预期工作。

with <code>.edgesIgnoringSafeArea</code>

但是我不知道我的自定义视图怎么了才能实现这一目标。

struct ExampleNavigationView<Content: View>: UIViewControllerRepresentable {
    private var content: () -> Content

    init(@ViewBuilder content: @escaping () -> Content){
        self.content = content
    }

    func makeUIViewController(context: Context) -> UINavigationController {
        let contentViewController = UIHostingController(rootView: content())
        let navigationController = UINavigationController(rootViewController: contentViewController)
        navigationController.navigationBar.prefersLargeTitles = false
        contentViewController.navigationItem.title = "Search"
        return navigationController
    }

    func updateUIViewController(_ uiViewController: UINavigationController, context: UIViewControllerRepresentableContext<ExampleNavigationView>) {}
}

0 个答案:

没有答案