Instance Method

keyboardType(_:)

Sets the keyboard type for this view.

Declaration

func keyboardType(_ type: UIKeyboardType) -> some View

Parameters

type

One of the keyboard types defined in the UIKeyboardType enumeration.

Discussion

Use keyboardType(_:) to specify the keyboard type to be used 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 UIKeyboardType.emailAddress ensures the user can only enter correctly formatted email addresses.

HStack {
    Text("Email")
    TextField("user-name@example.com", text: $emailAddress)
        .keyboardType(.emailAddress)
}
A screenshot of an email text entry field and an email-specific keyboard.

There are several different kinds of specialized keyboard types available though the UIKeyboardType enumeration. To specify the default system keyboard type, use UIKeyboardType.default.

See Also

Adjusting Text in a View

func font(Font?) -> View

Sets the default font for text in this view.

func lineLimit(Int?) -> View

Sets the maximum number of lines that text can occupy in this view.

func lineSpacing(CGFloat) -> View

Sets the amount of space between lines of text in this view.

func multilineTextAlignment(TextAlignment) -> View

Sets the alignment of multiline text in this view.

func minimumScaleFactor(CGFloat) -> View

Sets the minimum amount that text in this view scales down to fit in the available space.

func truncationMode(Text.TruncationMode) -> View

Sets the truncation mode for lines of text that are too long to fit in the available space.

func allowsTightening(Bool) -> View

Sets whether text in this view can compress the space between characters when necessary to fit text in a line.

func textContentType(UITextContentType?) -> View

Sets the text content type for this view, which the system uses to offer suggestions while the user enters text on an iOS or tvOS device.

func textContentType(WKTextContentType?) -> View

Sets the text content type for this view, which the system uses to offer suggestions while the user enters text on a watchOS device.

func flipsForRightToLeftLayoutDirection(Bool) -> View

Sets whether this view flips its contents horizontally when the layout direction is right-to-left.

func autocapitalization(UITextAutocapitalizationType) -> View

Sets whether to apply auto-capitalization to this view.

func disableAutocorrection(Bool?) -> View

Sets whether to disable autocorrection for this view.