【问题标题】:SwiftUI Custom Font Size inside Picker using SegmentedPickerStyleSwiftUI 使用 SegmentedPickerStyle 在 Picker 中自定义字体大小
【发布时间】:2020-07-02 02:45:10
【问题描述】:

我正在尝试自定义 Picker 中两个标签的字体大小。我正在使用 SegmentedPickerStyle,我希望 Picker 字体大小与我在表单上使用的其他标题/字符串的文本大小相匹配。其他字体使用 .font(.headline)

var body: some View {
NavigationView {
    ScrollView {
        VStack(alignment: .leading){
            Group {
                Picker("", selection: $form.nameType) {
                    Text("First/Last name \(form.nameType == 0 ? "*" : "")").tag(0)
                    Text("Company name \(form.nameType == 1 ? "*" : "")").tag(1)
                    }
                    .pickerStyle(SegmentedPickerStyle())    
                }
            }
        }
    }
}

【问题讨论】:

    标签: swiftui font-size picker


    【解决方案1】:

    你可以自定义你的段控制器的字体添加这个:

    init() {
            UISegmentedControl.appearance().setTitleTextAttributes(
                [
                    .font: UIFont.systemFont(ofSize: 18),
                ], for: .normal)
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-06-11
      • 1970-01-01
      • 2019-11-05
      • 2021-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多