Search code examples
iosswiftui

Add Text and Image to Button in SwiftUI


I'm trying to add both Text and Image on Button like:

Button(action: {}) {
        Image("gift")
        Text("Send")
            .padding(.horizontal)
    }
    .padding()
    .foregroundColor(.white)
    .background(Color.gray)
    .cornerRadius(.infinity)

Button looks:

enter image description here

But I want to create this:

enter image description here

Thanks


Solution

  • Just put the Image and Text inside an HStack

    Button(action: {}) {
        HStack {
            Image(systemName: "gift")
            Text("Send")
        }
    }
    .padding()
    .foregroundColor(.white)
    .background(Color.gray)
    .cornerRadius(.infinity)
    

    enter image description here