Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create an image button in SwiftUI

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?

like image 245
Aaron Bratcher Avatar asked Dec 29 '25 14:12

Aaron Bratcher


1 Answers

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

Image("Transactions").renderingMode(.original)    
like image 61
FunkyMan Avatar answered Jan 01 '26 11:01

FunkyMan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!