How do I create an image button in SwiftUI

Viewed 2372

I have the following code to show an image:

struct TransactionsButtonView : View {
    var body: some View {
        return VStack {
            Image("Transactions")
            Text("Transactions")
                .font(.footnote)
            }.padding(.horizontal)
    }
}

This creates an image properly:

Transactions Image

However when I try to convert it to an image button, it only shows blue:

struct TransactionsButtonView : View {
    var body: some View {
        return VStack {
            Button(action: { self.showTransactions() }) {
                Image("Transactions")
            }
            Text("Transactions")
                .font(.footnote)
            }.padding(.horizontal)
    }

    func showTransactions() {

    }
}

Blue Button

How do I get my button to show the image?

1 Answers

You have to modify your image with the renderingMode by adding the following property:

Image("Transactions").renderingMode(.original)    
Related