SwiftUI Picker 自定义文本颜色很快就不起作用
使用以下代码我正在创建一个选择器,但是自定义存在一个巨大的问题。
只有 .background(color.red)作品。
为什么对选择器感到痛苦。 Uiview Picker也是如此。
我找不到改变背景或文本颜色的方法。
Picker("what is this", selection: $selectedTray) {
ForEach(trayType, id: \.self) {
Text($0)
.multilineTextAlignment(.trailing)
.foregroundColor(Color.green)
.background(Color.blue)
}
}.foregroundColor(Color.white)
.background(Color.red)
Using following code I am creating a picker but there is a huge problem with customization.
Only .background(Color.red) works.
Why it has be pain with Picker.
It was the same with UIView Picker as well.
I could not find a way to change background or text color.
Picker("what is this", selection: $selectedTray) {
ForEach(trayType, id: \.self) {
Text($0)
.multilineTextAlignment(.trailing)
.foregroundColor(Color.green)
.background(Color.blue)
}
}.foregroundColor(Color.white)
.background(Color.red)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
目前尚不清楚您想要什么定制。在一部分中,您指出仅设置
.background()
颜色有效,在另一部分中,您指出“我找不到更改背景或文本颜色的方法”。显然,您已经找到了如何更改背景颜色。如果这不是您想要的,请发布图片或对您想要的内容进行很好的描述。
It is not clear what customizations you want. In one part you date that only setting the
.background()
color works, in another you state "I could not find a way to change background or text color." Obviously, you have found out how to change the background color.If this is not what you want, please post an image or a very good description of what you do want.
在
表单
中您需要应用
listrowbackground
设置背景颜色Inside a
Form
You need to apply the
listRowBackground
to set the background color