The most common way of getting some interaction from our App's users is through buttons.
There are many options to create a button, in this first article about buttons we'll explore the simplest way:
This component requires two things, action
and label
, which will be define between { }
.
Button(action: {
print("Button has been tapped")
}, label: {
Text("Tap here")
})
Action
All the code included here will be ignored until the user taps the button. In that moment those lines between action's { }
will execute. In our case we'll see a message in the console thanks to print()
command.
print()
won't work when using the Xcode Preview section, you need to run the simulator.
Label
On the other side, we added a Text
as a label, but you could use any UI component here.
Be the first to comment