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

SOLVED: Number Pad

Forums > watchOS

Does anyone know how to have a number pad show up on a text field using SwiftUI. Maybe it doesn’t even have to be a text field. I just need a way to input numbers for a calculation.

I'm currently using a slider but that's not the most efficient way of doing so.



On iOS use .keyboardType(.numberPad) but not sure

TextField("Some Number", text: $someText)

PS there are different Keyboards when you put the . in eg .decimalPad pick which one you want to use.


Did you try:

TextField("Something", text: $property).keyboardType(.decimal)

The string is the sample text that will show, it can be empty, and the text prarmeter is the @State property of your choice.

Not sure about watchOS but that's in SwiftUI.


There is no keyboard on watchOS, only the scatch pad. So enless you want to make your number pad like the Calc App or use a picker


Hi everyone, I made my own SwiftUI keypad for WatchOS! Here is the GitHub link. Hope it helps! Demo on 44mm Watch


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.