<!--
{
  "availability" : [
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "WatchKit",
  "identifier" : "/documentation/WatchKit/WKInterfaceTextField",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "WatchKit"
    ],
    "preciseIdentifier" : "c:objc(cs)WKInterfaceTextField"
  },
  "title" : "WKInterfaceTextField"
}
-->

# WKInterfaceTextField

An interface element that displays an editable text area.

```
class WKInterfaceTextField
```

## Overview

Text fields gather text-based input from the user. The text field defines an area of editable text within your user interface, letting you create forms with multiple input fields.

![A screenshot of a sample sign in screen.](images/com.apple.watchkit/media-3222854@2x.png)

When the user taps the text field, WatchKit displays the text input controller. Users can enter text by selecting one of the suggestions, or using dictation or Scribble. Users can also launch the Apple Continuity Keyboard, entering text from a nearby iOS device logged into the same iCloud account.

Use text fields to gather short, specific pieces of information such as the user’s name, address, password, or credit card number. Identify the type of data using the text field’s content type, which allows the system to optimize the behavior of the text input controller and the Apple Continuity Keyboard. For more information, see `Authenticating Users on Apple Watch`.

You can also describe the expected content to the user in the text field’s placeholder. Effective placeholders let you build a form that is both compact and easy to use.

For general text input, consider using [`presentTextInputController(withSuggestions:allowedInputMode:completion:)`](/documentation/WatchKit/WKInterfaceController/presentTextInputController(withSuggestions:allowedInputMode:completion:)) or [`presentTextInputControllerWithSuggestions(forLanguage:allowedInputMode:completion:)`](/documentation/WatchKit/WKInterfaceController/presentTextInputControllerWithSuggestions(forLanguage:allowedInputMode:completion:)) instead. Call these methods to display the text input controller with the suggestions that you provide. Keep in mind that the system doesn’t provide the text input controller with a content type, so the system cannot optimize its behavior.

### Configure the Text Field

As with other WatchKit interface objects, you should not subclass or create instances of this class. Instead, add a text field to your WatchKit App’s storyboard. The system then creates the text field when it loads the storyboard.

Xcode also lets you configure the text field directly in the storyboard. The following table lists the attributes and their meaning.

|Attribute        |Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
|-----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|Text             |The initial text displayed by the text field. Specify a plain string or an attributed string. You can set this value programmatically using the ``doc://com.apple.watchkit/documentation/WatchKit/WKInterfaceTextField/setText(_:)`` or ``doc://com.apple.watchkit/documentation/WatchKit/WKInterfaceTextField/setAttributedText(_:)`` methods.                                                                                                                                                                           |
|Placeholder      |The placeholder text displayed by the text field. When the text field’s value is empty, the text field displays the placeholder, formatting it to make it clear that it’s not an actual text entry. Typing any text into the text field hides this string. You can set this value programmatically using the ``doc://com.apple.watchkit/documentation/WatchKit/WKInterfaceTextField/setPlaceholder(_:)`` or ``doc://com.apple.watchkit/documentation/WatchKit/WKInterfaceTextField/setAttributedPlaceholder(_:)`` methods.|
|Text Color       |The color of the text. The system applies this color to the entire string. You can set this value programmatically using the ``doc://com.apple.watchkit/documentation/WatchKit/WKInterfaceTextField/setTextColor(_:)`` method.                                                                                                                                                                                                                                                                                            |
|Content Type     |The text field’s expected content, such as a username, password, or address. You can set this value programmatically using the ``doc://com.apple.watchkit/documentation/WatchKit/WKInterfaceTextField/setTextContentType(_:)`` method.                                                                                                                                                                                                                                                                                    |
|Secure Text Entry|A checkbox indicating whether the text field hides the text that the user entered, keeping passwords and other secure data private. You can set this value programmatically using the ``doc://com.apple.watchkit/documentation/WatchKit/WKInterfaceTextField/setSecureTextEntry(_:)`` method.                                                                                                                                                                                                                             |
|Enabled          |A checkbox indicating whether the text field  is enabled and responds when tapped. You can configure this value programmatically using the ``doc://com.apple.watchkit/documentation/WatchKit/WKInterfaceTextField/setEnabled(_:)`` method.                                                                                                                                                                                                                                                                                |

To dynamically modify a text field at runtime, define an outlet in your interface controller and connect it to the corresponding text field in your storyboard. For example, define a property with the following syntax in your interface controller class:

```objc
@property (weak, nonatomic) IBOutlet WKInterfaceTextField* myTextField;
```

During your interface controller’s initialization, WatchKit creates a new instance of the [`WKInterfaceTextField`](/documentation/WatchKit/WKInterfaceTextField) class and assigns it to your outlet. At that point, you can use the object in your outlet to manage the text field.

### Receive Text Input

To receive the text entered by the user, connect the text field in the storyboard to an action method defined in your interface controller.

```objc
- (IBAction)textFieldAction:(NSString*) value
```

WatchKit calls the action method after the user dismisses the text input controller. The `value` parameter contains the string entered by the user. If the user cancels the text input controller, the value is `nil`.

## Topics

### Specifying the Content Type

[`setTextContentType(_:)`](/documentation/WatchKit/WKInterfaceTextField/setTextContentType(_:))

Sets the text field’s semantic meaning.

[`WKTextContentType`](/documentation/WatchKit/WKTextContentType)

Constants that specify a text field’s semantic meaning.

### Setting the Text

[`setText(_:)`](/documentation/WatchKit/WKInterfaceTextField/setText(_:))

Sets the text displayed by the text field.

[`setAttributedText(_:)`](/documentation/WatchKit/WKInterfaceTextField/setAttributedText(_:))

Sets the styled text displayed by the text field.

[`setTextColor(_:)`](/documentation/WatchKit/WKInterfaceTextField/setTextColor(_:))

Sets the text’s color.

### Setting a Placeholder

[`setPlaceholder(_:)`](/documentation/WatchKit/WKInterfaceTextField/setPlaceholder(_:))

Sets the text field’s placeholder.

[`setAttributedPlaceholder(_:)`](/documentation/WatchKit/WKInterfaceTextField/setAttributedPlaceholder(_:))

Sets the text field’s placeholder using styled text.

### Configuring the Control

[`setEnabled(_:)`](/documentation/WatchKit/WKInterfaceTextField/setEnabled(_:))

Enables or disables the text field.

[`setSecureTextEntry(_:)`](/documentation/WatchKit/WKInterfaceTextField/setSecureTextEntry(_:))

Determines whether the text field hides the text entered by the user.

## See Also

[`presentTextInputController(withSuggestions:allowedInputMode:completion:)`](/documentation/WatchKit/WKInterfaceController/presentTextInputController(withSuggestions:allowedInputMode:completion:))

Displays a modal interface for gathering text input from the user.

[`presentTextInputControllerWithSuggestions(forLanguage:allowedInputMode:completion:)`](/documentation/WatchKit/WKInterfaceController/presentTextInputControllerWithSuggestions(forLanguage:allowedInputMode:completion:))

Displays a modal interface for gathering language-specific text input from the user.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)