-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Term Entry] SwiftUI Concept: Buttons #5809
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @botaturganova, thanks for contributing this entry. I have some suggestions, I have put some comments, please check them and do the required changes. Let me know if you have any questions.
In this example: | ||
|
||
The button displays an image and text. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add an image example here.
## Basic Button | ||
|
||
A simple button in SwiftUI is created using the `Button` view. You can pass a closure (action) to the button that will be executed when the button is tapped: | ||
|
||
```swift | ||
Button("Tap Me") { | ||
print("Button tapped!") | ||
} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "Basic Button" section largely overlaps with the "Creating Buttons" section. Consolidating these or adding new value to the second section will improve the flow.
// Action here | ||
} | ||
.disabled(true) | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add ButtonRole
Information (iOS 15+). The new ButtonRole
API in iOS 15+ allows buttons to have semantic roles like "destructive" or "cancel". Mentioning this improves completeness of this doc.
Starting in iOS 15, you can specify a `ButtonRole` (e.g., `.destructive` or `.cancel`) to provide semantic meaning to the button:
```swift
Button("Delete", role: .destructive) {
print("Delete action")
}
## Creating Buttons | ||
|
||
Buttons are created by specifying an action (code to execute when the button is tapped) and a label (the content of the button that is displayed to users). For example: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Buttons in SwiftUI can use multiple types of views as labels, not just Text
. This could be explicitly mentioned for beginners beforehand, but it should probably be covered in a Syntax
header, and then usage should be explained in examples.
Buttons in SwiftUI can use any SwiftUI view as a label, not just `Text`. This allows for highly customizable and complex button content, such as combining icons, shapes, or even animations.
.background(Color.blue) | ||
.cornerRadius(10) | ||
} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should include images and output on clicking the button in each case for good understanding.
Description
Issue Solved
Type of Change
Checklist
main
branch.