[英]Styling differences in SwiftUI Button in list context: iOS 15 vs. earlier
With this example:通过这个例子:
struct ContentView: View {
let items = ["Hello, world!"]
var body: some View {
List {
Button(action: {
}, label: {
Text("Hello, world!")
})
.listRowBackground(Color.gray)
}
}
}
on iOS 14, this looks like:在 iOS 14 上,这看起来像:
on iOS 15, it now looks like:在 iOS 15 上,它现在看起来像:
It is rather surprising the number of styling differences:样式差异的数量相当令人惊讶:
Is this just an expected change with iOS 15?这只是 iOS 15 的预期变化吗?
Is there a standard way to not have these changes occur?有没有标准的方法来避免这些变化发生? Ie, to retain the earlier styling?
即,保留较早的样式?
Yes, Apple has changed its default UI elements states.是的,Apple 已更改其默认 UI 元素状态。 This can also be seen in Safari where webpages have no CSS for forms.
这也可以在 Safari 中看到,其中网页没有用于表单的 CSS。
The specific answer that helped me was the use of .listStyle
.帮助我的具体答案是使用
.listStyle
。 In my original code, I didn't use .listStyle
, and apparently the default has changed.在我的原始代码中,我没有使用
.listStyle
,显然默认值已更改。 So, if I do:所以,如果我这样做:
struct ContentView: View {
let items = ["Hello, world!"]
var body: some View {
List {
Button(action: {
}, label: {
Text("Hello, world!")
})
.listRowBackground(Color.gray)
}
.listStyle(PlainListStyle())
}
}
I get a result closer to what I want.我得到了更接近我想要的结果。
Apparently the .listStyle
default is now insetGrouped
, which is not what I wanted.显然
.listStyle
默认值现在是insetGrouped
,这不是我想要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.