I want to remove the background gray box of the selection from the Picker view in SwiftUI, so that I can customize the complete view.
Picker view with gray background:
I want to remove the background gray box of the selection from the Picker view in SwiftUI, so that I can customize the complete view.
Picker view with gray background:
How about this? You can format the frame to be whatever you want (rounded edges, different colors, etc.)
import SwiftUI
struct Test: View {
init() {
UIPickerView.appearance().backgroundColor = .clear
}
enum Flavor: String, CaseIterable, Identifiable {
case chocolate
case vanilla
case strawberry
var id: String { self.rawValue }
}
@State private var selectedFlavor = Flavor.chocolate
var body: some View {
Picker("Flavor", selection: $selectedFlavor) {
Text("Chocolate").tag(Flavor.chocolate)
Text("Vanilla").tag(Flavor.vanilla)
Text("Strawberry").tag(Flavor.strawberry)
}
.frame(height: 30, alignment: .center)
.background(Color.blue)
}
}
struct Test_Previews: PreviewProvider {
static var previews: some View {
Test()
}
}
protocol PickerStyle {}