SwiftUI - TabView with NavigationView 生成灰色区域

标签 swift xcode user-interface swiftui ios13

当我将 isTranslucent 设置为 false 并结合 NavigationView 时,我的选项卡式 View 出现了一些问题。

有人知道怎么解决吗?问题如附图所示。

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

enter image description here

最佳答案

您可以设置背景颜色。不要将 isTranslucent 设置为 false,否则会产生您提到的这些人工制品。

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

它变得更暗了。不过它并非完全不透明。

编辑:刚刚观看了 Modernizing Your UI for iOS 13 这是这样做的方法:

TabView 和 NavigationView 实际上是遗留 UITabBarController 和 UINavigationController 的 UIHostedController:

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

然后在各种类型的外观上设置外观。

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。

引用:https://developer.apple.com/videos/play/wwdc2019/224/

关于SwiftUI - TabView with NavigationView 生成灰色区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58017776/

相关文章:

ios - 如何选择多行并将这些选项通过 prepareForSegue 函数发送到第二个 UITableView?

ios - AppDelegate中Viewcontroller的访问变量

xcode - 如何从 Storyboard添加设备 查看为

wpf - 如何制作具有交替行颜色和固定颜色部分的 WPF DataGrid(忽略交替)

java - 当用户点击红叉时如何显示确认消息? Java图形用户界面

ios - 从 AudioQueueBufferRef 输出队列回调中获取音频 float

swift - TokBox: 'consumeFrame' 在使用修改后的像素缓冲区时崩溃

ios - 在 xcode 中开发全屏 4 英寸应用程序

iOS 内部 podspec 安装不安装外部 Pod

python - tkinter 在 MacOS 上始终使窗口保持在顶部