[英]SwiftUI - I can not change the style of Picker's text on screen
I have a picker like this:我有一个这样的选择器:
Picker(languages[currentIndex].name,selection: $currentIndex){
ForEach(0..<languages.count, id: \.self){index in
Text(languages[index].name)
}
}
And it looks like this:它看起来像这样:
I'm trying to style the blue 'English' text that you see on the screenshot.我正在尝试设置您在屏幕截图中看到的蓝色“英文”文本的样式。 So far I've tried to give some styling to the Text, and the Picker itself but I could not succeed it.到目前为止,我已经尝试为 Text 和 Picker 本身赋予一些样式,但我无法成功。
The picker is meant to be in menu style, so I can not change the pickerStyle to another one (ie wheel).选择器是菜单样式,所以我不能将选择器样式更改为另一个(即轮子)。 I explicitly mentioned it because when I make it like this, it works:我明确提到了它,因为当我这样做时,它可以工作:
Picker(languages[currentIndex].name,selection: $currentIndex){
ForEach(0..<languages.count, id: \.self){index in
Text(languages[index].name)
.font(.custom("Montserrat Medium", size:16))
}
}.pickerStyle(.wheel)
However, this is not what I'm looking for.然而,这不是我要找的。 I only need to style this blue "English" text:我只需要设置这个蓝色“英文”文本的样式:
Thanks in advance.提前致谢。
As a workaround you can use Menu
instead of Picker
:作为一种解决方法,您可以使用Menu
而不是Picker
:
struct ContentView: View {
let languages = ["English", "German", "Spanish"]
@State private var currentIndex = 0
var body: some View {
Menu {
ForEach(0..<languages.count, id: \.self) { index in
Button {
currentIndex = index
} label: {
Text(languages[index])
}
}
} label: {
Text(languages[currentIndex])
.foregroundColor(.orange)
.bold()
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.