keyboardType

Sets the keyboard type for this view.

View ModifieriOS 13.0+tvOS 13.0+keyboardType(_:) in SwiftUI

Declaration

React
compose().keyboardType(
  type: 'default' | 'asciiCapable' | 'numbersAndPunctuation' | 'URL' | 'numberPad' | 'phonePad' | 'namePhonePad' | 'emailAddress' | 'decimalPad' | 'twitter' | 'webSearch' | 'asciiCapableNumberPad'
)
Swift
nonisolated func keyboardType(_ type: UIKeyboardType) -> some View

Parameters

  • type*'default' | 'asciiCapable' | 'numbersAndPunctuation' | 'URL' | 'numberPad' | 'phonePad' | 'namePhonePad' | 'emailAddress' | 'decimalPad' | 'twitter' | 'webSearch' | 'asciiCapableNumberPad'

    One of the keyboard types defined in the

Discussion

Use keyboardType(_:) to specify the keyboard type to use for text entry. A number of different keyboard types are available to meet specialized input needs, such as entering email addresses or phone numbers.

The example below presents a TextField to input an email address. Setting the text field's keyboard type to .emailAddress ensures the user can only enter correctly formatted email addresses.

TextField("someone@example.com", text: $emailAddress)
    .keyboardType(.emailAddress)

There are several different kinds of specialized keyboard types available though the doc://com.apple.documentation/documentation/UIKit/UIKeyboardType enumeration. To specify the default system keyboard type, use .default.

doc://com.apple.documentation/documentation/UIKit/UIKeyboardType enumeration.

See also

More in Text and symbols.