简体   繁体   English

如何更改 Picker 的字体?

[英]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附上一些参考资料来支持解释

  • When PickerStyle set to .wheel当 PickerStyle 设置为.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.第一个选择器项目为蓝色,字体较小,第二个项目为红色,字体较大。

  • When PickerStyle is set to .menu当 PickerStyle 设置为.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.

相关问题 如何在自动布局中更改选择器视图的字体大小 - how to change the font size of picker view in autolayout 如何使用Xamarin表单ios PickerRenderer更改Picker字体大小? - How to change Picker font size using Xamarin forms ios PickerRenderer? 如何在iOS Objective C中更改日期选择器视图和选择器视图的字体大小 - how to change font size of date picker view and picker view in iOS Objective C 在选择器视图中更改字体颜色 - Change the font color inside a Picker View 在Titanium中的iOS上更改选择器的字体颜色 - Change font colour of picker on iOS in Titanium 如何更改 UINavigationItem 字体? - How to change UINavigationItem font? 如何更改NSMutableAttributedString的默认字体和字体大小 - how to change the default font and font size of NSMutableAttributedString 如何更改字体颜色,字体名称和字体大小UIWebview? - How to change font color, font name and font size UIWebview? 如何将UIImage Picker相机方向更改为横向? - How to change the UIImage picker camera orientation to landscape? 如何在UIImage Picker控制器中更改图像大小 - How to change a image size in uiimage picker controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM