NEW: Start my new Ultimate Portfolio App course with a free Hacking with Swift+ trial! >>

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


Hacking with Swift is sponsored by Fernando Olivares

SPONSORED Would you describe yourself as knowledgeable, but struggling when you have to come up with your own code? Fernando Olivares has a new book containing iOS rules you can immediately apply to your coding habits to see dramatic improvements, while also teaching applied programming fundamentals seen in refactored code from published apps.

Try the book!

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

Reply to this topic…

You need to create an account or log in to reply.

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.