Buttons

Let's start by adding a Button to our app that has an image. The reason that we want Buttons—rather than just an image—is that we want the user to be able to interact with this control, which not only performs an action, but can also change the state of our app.

Let's start by heading over to our RecipeView.swift file and we'll work from there. To start with, make the following highlighted changes to the code, and we'll go through them one by one:

var body: some View {            Group {        VStack(alignment: .leading) {            Text("\(recipe.name)")                .font(.headline)                .foregroundColor(Color.blue)                .bold()                            Text("\(recipe.origin)")                .font(.subheadline)                .foregroundColor(Color.purple)                .italic()        }        VStack(alignment: .trailing, spacing: 10) { Button(action: { ...

Get Learn SwiftUI now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.