2

I'm trying to put a view inside of SegmentedPickerStyle Picker. The view I'm trying to put is just simple like this:

VStack{
Text("text1")
Text("text1")
}

And below are what I have tried to achieve this

try1

struct ContentView: View {
    @State private var selected = 0
    let options = ["AAA", "BBB"]
    var body: some View {
       Picker(selection: self.$selected, label: Text("")) {
        
        ForEach(0..<self.options.count) {number in
            VStack{
                Text("\(self.options[number])")
                Text("some text")
            }
      }
        }.pickerStyle(SegmentedPickerStyle())
    }
}

try2

struct ContentView: View {
    @State private var selected = 0
    let options = ["AAA", "BBB"]
    var body: some View {
       Picker(selection: self.$selected, label: Text("")) {
        
        ForEach(0..<self.options.count) {number in
            
                Text("""
                    \(self.options[number])
                    some text
                    """)
      }
        }.pickerStyle(SegmentedPickerStyle())
    }
}

But above both ways don't produce the result I want, Would be there anyway to achieve this?

1 Answer 1

2

Not supported for now. Here is what Apple says (pay attention on Note):

/// A picker style that presents the options in a segmented control.
///
/// To apply this style to a picker, or to a view that contains pickers, use the
/// ``View/pickerStyle(_:)`` modifier.
///
/// > Note: The segmented picker style supports ``Text`` and ``Image`` segments only.
/// Any other view results in a visible, but empty, segment.
@available(iOS 13.0, OSX 10.15, tvOS 13.0, *)
@available(watchOS, unavailable)
public struct SegmentedPickerStyle : PickerStyle {
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.