SwiftUI使用SegmentedPickerStyle在选择器内自定义字体大小
我试图自定义选择器中两个标记的字体大小。我使用的是SegmentedPickerStyle,我希望PickerFont大小与我在表单上使用的其他标题/字符串的文本大小相匹配。其他字体使用.font.headlineSwiftUI使用SegmentedPickerStyle在选择器内自定义字体大小,swiftui,font-size,picker,Swiftui,Font Size,Picker,我试图自定义选择器中两个标记的字体大小。我使用的是SegmentedPickerStyle,我希望PickerFont大小与我在表单上使用的其他标题/字符串的文本大小相匹配。其他字体使用.font.headline var body: some View { NavigationView { ScrollView { VStack(alignment: .leading){ Group { Picker("
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())
}
}
}
}
}
通过添加以下内容,您可以自定义分段控制器的字体:
init() {
UISegmentedControl.appearance().setTitleTextAttributes(
[
.font: UIFont.systemFont(ofSize: 18),
], for: .normal)
}
通过添加以下内容,您可以自定义分段控制器的字体:
init() {
UISegmentedControl.appearance().setTitleTextAttributes(
[
.font: UIFont.systemFont(ofSize: 18),
], for: .normal)
}