Yarm
Yarm

Reputation: 1328

How to hide border in swiftUI control?

Is it possible to hide a SwiftUI picker border? Possibly it belongs t some sub-layer.

By border, I mean the thin grey lines as per the image below.

enter image description here

import SwiftUI

struct TestView: View {

    @State private var selectedOption = "A"

    let options = ["A", "B", "C", "D", "E" ]

    var body: some View {

        VStack {
            Text(selectedOption)
            Picker(selection: self.$selectedOption, label: Text("Picker Name")) {
                ForEach(options, id: \.self) { option in
                    Text(option).rotationEffect(Angle(degrees: 90))
                }
            }
        .labelsHidden()
            .frame(width : 100, height : 30 )
        .rotationEffect(Angle(degrees: -90))
        }
    }
}

Upvotes: 2

Views: 1984

Answers (2)

jusynth
jusynth

Reputation: 191

You can do

UITableView.appearance().separatorColor = .clear

and then return your view

Upvotes: -1

Asperi
Asperi

Reputation: 257693

These grey lines is 'selection indicator' and it seems that Apple has same approach for SwiftUI as for UIKit UIPickerView, ie. show always.

Here is from Apple UIPickerView doc:
"Special Considerations
On iOS 7 and later you cannot customzie the picker view’s selection indicator. The selection indicator is always shown, so setting this property to false has no effect."

So no "official" way to do this... with Picker itself.

Upvotes: 3

Related Questions