SF Symbols Multicolored icons

1k views Asked by At

Im making an app with weather icons, and i wanted to use apple's SF Symbols! At WWDC2020 they released multicolred ones.

So my question is, why are my icons appearing in black like so:

enter image description here

I have set the rendering mode to alwaysOriginal. And it does nothing. If i set it to template it becomes blue, like the default tint color.

currentConditionImageView.image = UIImage(systemName: "cloud.sun.fill")!.withRenderingMode(.alwaysOriginal)

But according to the SF Symbols app, the symbol should look like this:

enter image description here

Has anyone encountered this Problem, and how did you solve it? Im looking forward to your answers!

2

There are 2 answers

2
matt On BEST ANSWER

The rule is:

In a template environment, such as a button, if you apply the .alwaysOriginal rendering mode to a multicolor symbol image, its inherent colors will appear.

But an image view is not a template environment. Try making this image the image (not the background image) of a UIButton.

enter image description here

If you put a multicolored image in a non-template environment, like an image view, you are basically misusing it if you make it .alwaysOriginal. You should just make it .alwaysTemplate and accept it as a monochrome image adopting the tint color.

enter image description here

2
adamup On

It is possible to create a multicolored SF Symbol for use in a non-template environment like UIImageView.

For a white checkmark on a green background, for example:

enter image description here

Try this:

let config = UIImage.SymbolConfiguration(paletteColors: [.white, UIColor.green])
  
let multicolorCheckmarkImage = UIImage(systemName: "checkmark.circle.fill")?.withConfiguration(config)
        
self.checkmarkImageView.image = multicolorCheckmarkImage