67

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.

peterh
  • 11,875
  • 18
  • 85
  • 108
Sajjad
  • 1,536
  • 2
  • 17
  • 31

5 Answers5

59

Another way to set programmatically:-

var body: some View {
        Button(action: {
          print("button pressed")

        }) {
            Image("marker")
            .renderingMode(Image.TemplateRenderingMode?.init(Image.TemplateRenderingMode.original))
        }
    }
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56
36

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

souvickcse
  • 7,742
  • 5
  • 37
  • 64
32

You can try this:

var body: some View {
        Button(action: {
          print("button pressed")

        }) {
            Image("marker")
            .renderingMode(.original)
        }
    }
Dino
  • 7,779
  • 12
  • 46
  • 85
Zack Shapiro
  • 6,648
  • 17
  • 83
  • 151
  • 6
    While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – Martin Wickman Nov 01 '19 at 13:52
8

SwiftUI

var body: some View {
      HStack {
           Image(uiImage: UIImage(named: "Login")!)
                .renderingMode(.original)
                .font(.title)
                .foregroundColor(.blue)

           Text("Login")
                .font(.title)
                .foregroundColor(.white)
      }
}
Rohit Makwana
  • 4,337
  • 1
  • 21
  • 29
Srinivasan_iOS
  • 972
  • 10
  • 12
0

Two ways to do this

  • 1st through the attribute inspector -

enter image description here

  • 2nd through .renderingMode() modifier -
Image("ImageName")    
   .resizable()    
   .renderingMode(.original)   
   .frame(width: 22, height: 22)
Anubhav Singh
  • 905
  • 6
  • 5