Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a button with image in SwiftUI?

Tags:

swift

swiftui

I created a button in SwiftUI with these line of codes:

Button(action: {     print("button pressed") }) {     Image("marker") } 

but marker image automatically changes to blue color.

I want to use original image in button.

this is original marker.png:

enter image description here

but SwiftUI changes it to this:

enter image description here

I remember we have tintColor or something like this in UIButton, but I can't find it in SwiftUI.

like image 207
Sajjad Avatar asked Jun 29 '19 20:06

Sajjad


2 Answers

Another way to set programmatically:-

var body: some View {         Button(action: {           print("button pressed")          }) {             Image("marker")             .renderingMode(Image.TemplateRenderingMode?.init(Image.TemplateRenderingMode.original))         }     } 
like image 161
Hussain Shabbir Avatar answered Sep 22 '22 22:09

Hussain Shabbir


Go to the image and change the Render As "Original Image" enter image description here

like image 44
souvickcse Avatar answered Sep 19 '22 22:09

souvickcse