Structure

SecureField

A control into which the user securely enters private text. それへとユーザが安全にプライベートテキストを入力するあるコントロール。

Declaration 宣言

struct SecureField<Label> where Label : View

Overview 概要

Use a SecureField when you want behavior similar to a TextField, but you don’t want the user’s text to be visible. Typically, you use this for entering passwords and other sensitive information.

A SecureField uses a binding to a string value, and a closure that executes when the user commits their edits, such as by pressing the Return key. The field updates the bound string on every keystroke or other edit, so you can read its value at any time from another control, such as a Done button.

The following example shows a SecureField bound to the string password. If the user commits their edit in the secure field, the onCommit closure sends the password string to a handleLogin() method.


@State private var username: String = ""
@State private var password: String = ""


var body: some View {
    TextField(
        "User name (email address)",
        text: $username)
        .autocapitalization(.none)
        .disableAutocorrection(true)
        .border(Color(UIColor.separator))
    SecureField(
        "Password",
        text: $password
    ) {
        handleLogin(username: username, password: password)
    }
    .border(Color(UIColor.separator))
}

Two vertically arranged views, the first a text field that displays the

SecureField Prompts

A secure field may be provided an explicit prompt to guide users on what text they should provide. The context in which a secure field appears determines where and when a prompt and label may be used. For example, a form on macOS will always place the label alongside the leading edge of the field and will use a prompt, when available, as placeholder text within the field itself. In the same context on iOS, the prompt or label will be used as placeholder text depending on whether a prompt is provided.


Form {
    TextField(text: $username, prompt: Text("Required")) {
        Text("Username")
    }
    SecureField(text: $username, prompt: Text("Required")) {
        Text("Password")
   }
}

Topics 話題

Creating a Secure Text Field

Configuring Text Entry

Supporting Types 支援を行う型

Deprecated Initializers

Default Implementations 省略時実装

Relationships 関係

Conforms To 次に準拠

See Also 参照

Text Entry