[英]How to change the font of a Picker?
I want to change a font of a Picker to Title2 (eg to.font(Font.title2.weight(.heavy)) ) so it's of a size and type Unfortunately, it doesn't read any font mentions and still display super small font.我想将 Picker 的字体更改为 Title2 (例如 to.font(Font.title2.weight(.heavy)) )所以它的大小和类型不幸的是,它没有读取任何字体提及并且仍然显示超小字体。
Here's my code (I got rid of any of my failed experiments):这是我的代码(我摆脱了任何失败的实验):
struct PlayView: View {
@State private var selectedLevel = "3"
let levels = ["1", "2", "3", "4", "5"]
@State private var selectedLife = "3"
let lives = ["1", "2", "3", "4", "5"]
@State private var selectedLetterMethod = "Sound"
let letters = ["Sound", "Written"]
@State private var showWelcomeView = false
var body: some View {
ZStack {
VStack() {
HStack{
Text("N:")
.font(Font.title2.weight(.heavy))
Picker("Level (n)", selection: $selectedLevel)
{
ForEach(levels, id: \.self) {
Text($0)
.font(.title2)
}
}
}
HStack{
Text("Lives:")
.font(Font.title2.weight(.heavy))
Picker("Lives", selection: $selectedLife) {
ForEach(lives, id: \.self) {
Text($0)
}
}
}
HStack{
Text("Letters:")
.font(Font.title2.weight(.heavy))
Picker("Letter display", selection: $selectedLetterMethod) {
ForEach(letters, id: \.self) {
Text($0)
}
}
}
If you set your pickerStyle
to .wheel
it will reflect all the font changes that you set.如果您将您的
pickerStyle
设置为.wheel
,它将反映您设置的所有字体更改。
As per your code as there is no pickerStyle the default is set to .menu
and no font styling will be applied when its .menu
.根据您的代码,因为没有 pickerStyle 默认设置为
.menu
,并且在其.menu
时不会应用字体样式。
Attaching a few references to support the explanation附上一些参考资料来支持解释
.wheel
.wheel
If you notice I have 2 picker items with different font styles and both are applied properly when .pickerStyle
is set to .wheel
如果您注意到我有 2 个不同字体的选择器项目 styles 并且当
.pickerStyle
设置为.wheel
时两者都正确应用
The first picker item as blue with a smaller font and the second item has red color with a bigger font.第一个选择器项目为蓝色,字体较小,第二个项目为红色,字体较大。
.menu
.menu
if the pickerStyle
is set to .menu
it shows up like below even with the same font styling如果选择器样式设置为
pickerStyle
,即使字体样式相同,它.menu
如下所示
Inorder to apply any font styling you should set your Picker's pickerStyle
value to .wheel
为了应用任何字体样式,您应该将 Picker 的
pickerStyle
值设置为.wheel
Your output would be something like this你的 output 会是这样的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.