.keyboardType()
Published Feb 26, 2023
Contribute to Docs
The .keyboardType()
view modifier method in SwiftUI is used to specify the keyboard type from the UIKeyboardType
enumeration to use for text entry.
Note: This method is specifically for use with text entry, so it can be applied as a view modifier to any view that accepts text input from the user, like a
TextField
.
Syntax
TextField("Some label", text: $someValueBinding)
.keyboardType(parameter)
This method has one required parameter:
type
: One of the keyboard types defined in theUIKeyboardType
enumeration.
Example
The following example demonstrates how to use the .keyboardType()
method to ensure the user can enter a correctly formatted email address:
.keyboardType(.emailAddress)
This will display:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn SwiftUI on Codecademy
- Skill path
Build iOS Apps with SwiftUI
Learn how to build iOS applications with Swift and SwiftUI and publish them to Apples' App Store.Includes 7 CoursesWith CertificateBeginner Friendly13 hours - Free course
Learn Swift
A powerful programming language developed by Apple for iOS, macOS, and more.Beginner Friendly12 hours