Protocol

View

A type that represents part of your app’s user interface and provides modifiers that you use to configure views. ある型、それはあなたのアプリのもつユーザインターフェイスの一部を表します、そしてあなたがビューを構成設定するのに使う修飾子を提供します。

Declaration 宣言

protocol View

Overview 概要

You create custom views by declaring types that conform to the View protocol. Implement the required body computed property to provide the content for your custom view.


struct MyView: View {
    var body: some View {
        Text("Hello, World!")
    }
}

Assemble the view’s body by combining one or more of the built-in views provided by SwiftUI, like the Text instance in the example above, plus other custom views that you define, into a hierarchy of views. For more information about creating custom views, see Declaring a Custom View.

The View protocol provides a set of modifiers — protocol methods with default implementations — that you use to configure views in the layout of your app. Modifiers work by wrapping the view instance on which you call them in another view with the specified characteristics, as described in Configuring Views. For example, adding the opacity(_:) modifier to a text view returns a new view with some amount of transparency:


Text("Hello, World!")
    .opacity(0.5) // Display partially transparent text.

The complete list of default modifiers provides a large set of controls for managing views. For example, you can fine tune Layout Modifiers, add Accessibility Modifiers information, and respond to Input and Event Modifiers. You can also collect groups of default modifiers into new, custom view modifiers for easy reuse.

Topics 話題

Implementing a Custom View カスタムビューを実装する

Configuring View Elements

Drawing Views

Providing Interactivity 相互作用性を提供する

Deprecated Modifiers

Relationships 関係

Conforming Types これらの型が準拠

See Also 参照

View Composition