textContentType

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.

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

Declaration

React
compose().textContentType(
  textContentType: ('name' | 'givenName' | 'familyName' | 'nickname' | 'organizationName' | 'fullStreetAddress' | 'postalCode' | 'telephoneNumber' | 'emailAddress' | 'URL' | 'creditCardNumber' | 'username' | 'password' | 'newPassword' | 'oneTimeCode' | (string & {})) | null
)
Swift
nonisolated func textContentType(
    _ textContentType: UITextContentType?
) -> some View

Parameters

  • textContentType*('name' | 'givenName' | 'familyName' | 'nickname' | 'organizationName' | 'fullStreetAddress' | 'postalCode' | 'telephoneNumber' | 'emailAddress' | 'URL' | 'creditCardNumber' | 'username' | 'password' | 'newPassword' | 'oneTimeCode' | (string & {})) | null

    One of the content types available in the doc://com.apple.documentation/documentation/UIKit/UITextContentType structure that identify the semantic meaning expected for a text-entry area. These include support for email addresses, location names, URLs, and telephone numbers, to name just a few.

Discussion

Use this method to set the content type for input text. For example, you can configure a TextField for the entry of email addresses:

TextField("Enter your email", text: $emailAddress)
    .textContentType(.emailAddress)

See also

More in Text and symbols.