It is a way to do not change the color of the Image in the Button with SwiftUI. If you keep the default, the color will change to blue as in the following image.
By setting renderingMode(.original)
the color of the original image was displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
Button(action: { | |
print("Tapped") | |
}) { | |
Image("icon") | |
.resizable() | |
.renderingMode(.original) | |
.frame(width: 32, height: 32) | |
Text("Tap Me!!") | |
.foregroundColor(Color.black) | |
} | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |