UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Change to Picker in iOS15?

Forums > SwiftUI

I want a menu in the toolbar. So I have this:

            .toolbar {
                Picker(selection: $which, label: Image(systemName: "text.justify")
                        .font(.title) 
                        .frame(width: 50, height: 20, alignment: .trailing)) {
                    ForEach(Destination.allCases, id: \.self) {
                        Text(getTabTitle($0)).foregroundColor(Color(UIColor.systemBlue))
                    }
                }
                .pickerStyle(MenuPickerStyle())

It works just fine. In iOS14, the picker title was four horizontal lines, which was what I wanted. But in iOS15, the title of the picker has changed: it ignores the label: parameter and displays whatever was last selected in the menu. How can I change it back to showing the Image?

(Destination is CaseIterable and getTabTitle returns String describing the Destination.)

Jeremy

2      

Would one of the label styles work for you?

.labelStyle(.automatic)
.labelStyle(.titleAndIcon)
.labelStyle(.iconOnly)
.labelStyle(.titleOnly)

Or use makeBody to make your own custom label style.

2      

Thanks Green, but that doesn't help. Wrapping the Picker in a Menu with a label works, though.

        .toolbar {
            Menu(content: {
                Picker("Destination", selection: $which) {
                    ForEach(Destination.allCases, id: \.self) {
                        Text(getTabTitle($0)).foregroundColor(Color(UIColor.systemBlue))
                    }
                }
            },
                 label: { Label ("Destination", systemImage: "text.justify") })
        }

3      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.