I want to set some font styling in a Picker with SegmentedPickerStyle(). But any font formatting is ignored. Is there a way to set the font for a segmentedPicker? I am pretty sure that it works for the default pickerWheel..
import UIKit
import PlaygroundSupport
import SwiftUI
// Make a SwiftUI view
struct ContentView: View {
@State private var selection: Int = 2
var body: some View {
Picker("", selection: self.$selection) {
Text("Shape").tag(0)
Text("Height").tag(1)
Text("Media").tag(2).font(.headline)
}
.font(.headline)
.cornerRadius(8)
.padding(10)
.pickerStyle(SegmentedPickerStyle())
}
}
// Make a UIHostingController
let viewController = UIHostingController(rootView: ContentView())
// Assign it to the playground's liveView
PlaygroundPage.current.liveView = viewController
// RUN!
SwiftUI uses UIKit (for iOS) under the hood, You should use appearance for UISegmentedControl
:
struct ContentView: View {
init() {
UISegmentedControl.appearance().selectedSegmentTintColor = .red
UISegmentedControl.appearance().setTitleTextAttributes(
[
.font: UIFont.boldSystemFont(ofSize: 24),
.foregroundColor: UIColor.white
], for: .selected)
UISegmentedControl.appearance().setTitleTextAttributes(
[
.font: UIFont.boldSystemFont(ofSize: 12),
.foregroundColor: UIColor.blue
], for: .normal)
}
var body: some View { ,,, }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With