gpt4 book ai didi

ios - 在 swiftUI 中为包含 List/Tableview 的全屏添加背景色

转载 作者:行者123 更新时间:2023-12-05 05:37:46 24 4
gpt4 key购买 nike

我想在 SwiftUI 中更改整个屏幕(包括安全区域)的背景颜色。

将以下代码添加到最外层 View 适用于所有 View ,除非给定 View 包含 List

.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.red)

我想为包含列表的全屏添加背景色。我试过很多东西,比如,

添加第一个元素为 Color.redZStack,但没有成功

Color.redList 作为叠加层,但它仍然无效。

唯一对我有用的是将 List 转换为 ScrollView,但我不想要。

有没有人有任何其他解决方案来实现这一点,或者 Apple 不提供更改 List 的背景颜色?(至少应该支持从 iOS14 到最新版本)

最佳答案

更新:Xcode 14b4 - 新测试版,新乐趣。

Xcode 14 上有新的修饰符(Xcode 14b4):

enter image description here

var body: some View {
List {
Text("Item 1")
Text("Item 2")
Text("Item 3")
}
//.scrollContentBackground(Color.blue) // << absent now !!
.scrollContentBackground(.hidden) // Xcode 14b4+
.background(Color.blue) // << also this needed !!
}

关于ios - 在 swiftUI 中为包含 List/Tableview 的全屏添加背景色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73061207/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com