set background color of [UIImage systemImageNamed: ... ]

hello all,

any idea if you can set the background color of one of these new SFSymbol images?

i tried this paletteColors: method, it seems to take only the first color and use it as the foreground color

 
UIImageSymbolConfiguration * config =

        [UIImageSymbolConfiguration configurationWithPaletteColors:@[[UIColor blueColor], [UIColor redColor]]];



    UIImage * confMatImageSel = [UIImage systemImageNamed:@"square.grid.2x2"

            withConfiguration:config];


Replies

It is probably because this symbol has not hierarchical layer.

When you create an image with this configuration, the system applies each color to the corresponding layer in the symbol layer hierarchy. 

If the symbol has only two nonconsecutive layers (primary and tertiary), specifying two colors applies the second color to the tertiary layer. Specifying three colors ignores the second color and applies the third color to the tertiary layer.

For this color configuration to have an effect, your symbol image must have the following:

Its renderingMode set to UIImage.RenderingMode.alwaysTemplate or UIImage.RenderingMode.automatic.

Hierarchical layer annotations. If your symbol doesn’t have hierarchical layer annotations, the resulting image is a monochrome (template) symbol image.

I tested with another symbol (Swift but so easy to adapt to objc):

               let config = UIImage.SymbolConfiguration(paletteColors: [.red, .blue])
               
               let image = UIImage(systemName: "person.crop.circle.badge.plus.fill", withConfiguration: config)!.withRenderingMode(.automatic) // "square.grid.2x2.fill"
               testImage.image = image

Here is the result on a yellow background. It takes the 2 colors for the symbol.

Changing blue to green:

               let config = UIImage.SymbolConfiguration(paletteColors: [.red, .green])

thanks, do you know if you can change the yellow part of it to another color?