SwiftUI Picker on iPadOS 15 beta 8

Something about the Picker label seems to have changed in iPadOS 15. The following View uses the version of Picker's init() marked for deprecation, but changing the deployment target from 14.5 to 15.0 and using the new version doesn't change the behavior. The first .gif shows the expected behavior that we've been seeing until 15.0. Notice in the second .gif that the label is hidden, and that the frame modifier is ignored. An extra Text view has been added to show that the binding is working as expected.

iPadOS 14.5 target / Xcode 12.5.1

iPadOS 15.0 target / Xcode 13.0 Beta 5

struct OuterView: View {

    @State var colorViewModel = ColorViewModel()

    var body: some View {

        ColorView(colorViewModel: colorViewModel)

    }

}



class ColorViewModel: ObservableObject {

    @Published var colors = ["yellow", "green", "blue"]

    @Published var selectedColor = "Select a color"

}



struct ColorView: View {

    @ObservedObject var colorViewModel: ColorViewModel



    var body: some View {

        VStack {

            Picker(selection: $colorViewModel.selectedColor,

                   label: Text(colorViewModel.selectedColor)

                    .frame(maxWidth: .infinity, alignment: .leading)

                    .padding()

                ) {

                ForEach(colorViewModel.colors, id: \.self) { color in

                    Text(color) }

                    }

            .pickerStyle(MenuPickerStyle())

            .border(Color.black, width: 2)



            Text(colorViewModel.selectedColor)

        }

        .padding()

    }

}



struct ColorView_Previews: PreviewProvider {

    static var previews: some View {

        OuterView()

    }

}

We are seeing the same issue on our app. Was hoping that this would be fixed before iOS 15 is released... probably next week or soon? Do we need to hot fix our application to support this type of picker style?

For anyone else running into this, it's not hard to convert from a Picker with MenuPickerStyle to a Menu. I went ahead and converted the above to demonstrate:

struct OuterView: View {
    @State var colorViewModel = ColorViewModel()

    var body: some View {
        ColorView(colorViewModel: colorViewModel)
    }
}

class ColorViewModel: ObservableObject {
    @Published var colors = ["yellow", "green", "blue"]
    @Published var selectedColor = "Select a color"
}

struct ColorView: View {
    @ObservedObject var colorViewModel: ColorViewModel

    var body: some View {
        VStack {
            Menu {
                ForEach(colorViewModel.colors, id: \.self) { color in
                    Button(color) {
                        colorViewModel.selectedColor = color
                    }
                }
            } label: { Text(colorViewModel.selectedColor)
                .frame(maxWidth: .infinity, alignment: .leading)
                .padding()
            }
            .border(Color.black, width: 2)

            Text(colorViewModel.selectedColor)
        }
        .padding()
    }
}

struct ColorView_Previews: PreviewProvider {
    static var previews: some View {
        OuterView()
    }
}

I'm having the same issue but with iOS 15. The label of the Picker simply doesnt work as expected in iOS 14.X

I already tried many things but nothing seems to work.

                Picker(selection: $selectedValue, label: formFieldDropdown,
                       content: {
                    ForEach(dataSource) {
                        Text($0.displayName)
                    }
                })
                    .pickerStyle(MenuPickerStyle())

iOS 14.X

iOS 15

Also, I'm unable to style the label text. Only .accentColor() can be set, but not custom fonts/sizes… Worked in iOS 14.

A scrolling Picker which displays just fine in 14.5 is just showing as a fixed text which the current selection. The actual picker does not show at all.

                Picker(“MyPicker”, selection: self.$viewModel.selection, content: {

                    ForEach(…)

                    })

                })

We need an immediate fix. Any hints or links appreciated. We will try the 15.1 beta to see whether this has been fixed. UPDATE: problem persists in 15.1.

Additional question: How could we have avoided this problem? Did we miss something in the documentation?

SwiftUI Picker on iPadOS 15 beta 8
 
 
Q