我看过几篇讨论如何在 SwiftUI 中制作透明导航栏的帖子,但没有关于如何制作半透明导航栏,这让我感到惊讶,因为它是 Apple 默认应用程序中非常常见的模式。例如笔记应用程序:
您可以通过导航栏查看绘图。任何人都知道如何做到这一点,最好是在明/暗模式下工作?
也许您只需要在 SwiftUI 视图中添加半透明设置
init() {
UINavigationBar.appearance().isTranslucent = true
}
Run Code Online (Sandbox Code Playgroud)
替代是完全重置外观,例如
init() {
let appearance = UINavigationBarAppearance()
appearance.configureWithTransparentBackground()
appearance.backgroundColor = UIColor.systemBackground.withAlphaComponent(0.5)
UINavigationBar.appearance().standardAppearance = appearance
}
Run Code Online (Sandbox Code Playgroud)
使用 Xcode 12 / iOS 14 准备和测试的演示
| 归档时间: |
|
| 查看次数: |
784 次 |
| 最近记录: |