NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

Other/custom text input in picker

Forums > SwiftUI

Hi everyone,

I'm just getting started on my Swift/UI journey, coming over from web/React land. I'm so grateful all the content here and the community.

I just finished the WeSplit app and I have a question about Picker. Let's say we want to give the user an easy way to pick common values for number of people, say 2 to 6. Then give them the ability to manually enter in values greater than 6.

Is there a standard iOS way to do this? I tried adding a TextField at the end of the Picker selections. However I got stuck trying to tie its state back to the Picker's bound state.



Hi shunicorn

While I think I understand what you want to do, however think the Picker is the to restrict to a list of items etc. So you would need to make a custom picker.

A video from Stewart Lynch Reuable Custom PickerView for SwiftUI might help you get in the direction you want.



You will need to handle the numbers out of the picker range yourself with whatever processing maybe necessary for a maximum, or minimum range of numbers (outside the picker range).

@State var anumber: String = ""

var commonNumbers: [String] = ["2","3","4","5","6"]

var body: some View {
    VStack(alignment: .leading) {
        Text("Tap a number to choose it")
        Picker("Pick a number", selection: $anumber) {
            ForEach(commonNumbers, id: \.self) { aNumber in
                Image(systemName: "\(aNumber).circle.fill")

    HStack {
        Text("Manual entry")
        TextField("Input number", text: $anumber)

    Text("Chosen number is \(anumber == "" ? "nothing yet" : anumber)")


Thanks @NigelGee. The custom PickerView looks cool. I'll try that out.


@Greenamberred thanks for your ideas as well. I think it might be good to only show the manual text field if the user selects an Other option or something like that. Will play with it!


Hacking with Swift is sponsored by Judo

SPONSORED Let’s face it, SwiftUI previews are limited, slow, and painful. Judo takes a different approach to building visually—think Interface Builder for SwiftUI. Build your interface in a completely visual canvas, then drag and drop into your Xcode project and wire up button clicks to custom code. Download the Mac App and start your free trial today!

Try now

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.