Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Picker default value a placeholder

Is it possible to set a placeholder text for a Swift Picker? I've been trying to search for a helpful answer but I haven't been successful so far.

Currently, when passing available list values to the Picker, I also pass it a default value to start with. However, this default value is treated the same as if the user picked it. What I'm trying to achieve is that the default value should be grayed out (like regular placeholders for standard textfields) and when the user opens the picker that value would 'disappear' as default forcing the user to pick something from the list (but without losing the range) -

So for example, if I have a picker for values between 1-200 and I set my placeholder to 100 the picker would still show this value when you open it (to avoid scrolling from the beginning) but it wouldn't be directly taken as the target value unless the user actually selects it.

like image 239
LisekKL Avatar asked Aug 13 '26 11:08

LisekKL


1 Answers

A Menu may be a better option than a Picker in this instance.

Menu("Label") {
    Button("Menu Item", action: menuAction)
    Button("Other Menu Item", action: otherMenuAction)
}

Menu Documentation

like image 102
David Zulaica Avatar answered Aug 16 '26 02:08

David Zulaica