1

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:

Picker view with gray background

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Cloudy of Sky
  • 103
  • 1
  • 7
  • Duplicates https://stackoverflow.com/questions/58668553/how-to-hide-border-in-swiftui-control. – Asperi Apr 05 '21 at 10:34
  • No :( I tested and this is not working. This part of the ui is not from a tableview and not from a segmented control. – Cloudy of Sky Apr 05 '21 at 10:52
  • try this :- **https://stackoverflow.com/a/51339952/11224009** – Saurav_Sharma Apr 05 '21 at 11:25
  • Welcome to SO - Please take the [tour](https://stackoverflow.com/tour) and read [How to Ask](https://stackoverflow.com/help/how-to-ask) to improve, edit and format your questions. Without a [Minimal Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) it is impossible to help you troubleshoot. – lorem ipsum Apr 05 '21 at 12:06
  • @CloudyofSky you found solution? – AndrewSas Oct 22 '21 at 13:03

1 Answers1

1

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 {}