Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I make my logo into a button in swiftUI?

I’m trying to get an image of a logo to be a button. I’m new to Swift/SwiftUI and the resources I’ve found so far seem to be outdated information. I have the image loaded in to see that I can get the image in there, and I’ve created a button in the location I want it, I just want to combine the two. Code is below.

struct ContentView: View {
var body: some View {
    VStack {
        Image("logo1024")
            .resizable()
            .padding()
            .frame(width: 120, height: 120)
            
        


        
        Group{
            
            Button(action: {
                print("tapped!")
            }, label: {
                Text("+")
                    .foregroundColor(.white)
                    .frame(width: 40, height: 40)
                    .background(Color.green)
                    .cornerRadius(15)
                    .padding()
            })
        }.frame(maxHeight: .infinity, alignment: .bottom)
    }
}

}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Just place image instead of Text into button (all other modifiers on your needs), like

    Group{
        
        Button(action: {
            print("tapped!")
        }, label: {
             Image("logo1024")
                .resizable()
                .padding()
                .frame(width: 120, height: 120)
                .foregroundColor(.white)
                .frame(width: 40, height: 40)
                .background(Color.green)
                .cornerRadius(15)
                .padding()
        })
    }.frame(maxHeight: .infinity, alignment: .bottom)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading