SwiftUI-具有NavigationView的TabView生成灰色区域 [英] SwiftUI - TabView with NavigationView generates gray area

查看:141
本文介绍了SwiftUI-具有NavigationView的TabView生成灰色区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将 isTranslucent 设置为 false 并与 NavigationView 结合使用时,选项卡式视图出现了一些问题.

I have some problems with my tabbed view when I set isTranslucent to false in combination with a NavigationView.

有人知道如何解决此问题吗?该问题显示在所附的图像中.

Does anyone know how to fix this? The problem is shown in the attached image.

我需要将半透明设置为false,否则我将无法获得深色.

I need translucent set to false otherwise I can't get the dark color.

推荐答案

您可以设置backgroundColor.不要将isTranslucent设置为false,否则会创建您提到的这些伪像.

You can set backgroundColor. Don't set isTranslucent to false or it will create these artefacts you mentioned.

UITabBar.appearance().backgroundColor = .black
UINavigationBar.appearance().backgroundColor = .black

它变得更黑了.但是它并不完全不透明.

It becomes much darker. It isn't completely opaque though.

刚刚观看了iOS 13的UI现代化方法:

Just watched Modernizing Your UI for iOS 13 This is the way to do it :

TabView和NavigationView实际上是用于旧版UITabBarController和UINavigationController的UIHostedController:

The TabView and NavigationView are actually UIHostedController for the legacy UITabBarController and UINavigationController:

let appearance = UITabBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.titleTextAttributes = [.foregroundColor: UIColor.white]
appearance.largeTitleTextAttributes = [.foregroundColor: UIColor  .white]

然后将外观设置为各种外观.

Then set the appearance on the various type of appearance.

tabBar.standardAppearance = appearance

第二次

extension UINavigationController {
    override open func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        let appearance = UINavigationBarAppearance()
        appearance.configureWithOpaqueBackground()
        navigationBar.standardAppearance = appearance
        navigationBar.compactAppearance = appearance
        navigationBar.scrollEdgeAppearance = appearance
    }
}

extension UITabBarController {
    override open func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        let appearance = UITabBarAppearance()
        appearance.configureWithOpaqueBackground()
        tabBar.standardAppearance = appearance
    }
}

应该有一种更干净的方法来同时访问tabBar和navBar.

There should be a cleaner way to get to both tabBar and navBar.

参考: https://developer.apple.com/videos/play/wwdc2019/224/

这篇关于SwiftUI-具有NavigationView的TabView生成灰色区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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