0% found this document useful (0 votes)
2 views1 page

Button

The document provides examples of creating a custom button in SwiftUI with a 'Sign In' label. It demonstrates two methods: using a single closure for the action and label, and using multiple trailing closures. It also explains the parameters for the button, including the action to perform and the label view.

Uploaded by

jon.moses2000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Button

The document provides examples of creating a custom button in SwiftUI with a 'Sign In' label. It demonstrates two methods: using a single closure for the action and label, and using multiple trailing closures. It also explains the parameters for the button, including the action to perform and the label view.

Uploaded by

jon.moses2000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Creates a button that displays a custom label.

struct SignInView: View {


var body: some View {
Button(action: { /* sign the user in */ }) {
Text("Sign In")
}
}
}

![Button with text reading "Sign in".](button-signin.png)

You can also use multiple trailing closure syntax to accomplish


the same task:

struct SignInView: View {


var body: some View {
Button {
/* sign the user in */
} label: {
Text("Sign In")
}
}
}

![Button with a textview reading "Sign in" as its label. ](button-init.png)

- Parameters:
- action: The action to perform when the user triggers the button.
- label: A view that describes the purpose of the button's `action`.
The content and behavior of the view.
The type of view representing the body of this view.

When you create a custom view, Swift infers this type from your
implementation of the required `body` property.

You might also like