Is there a way to use a specific locale for a SF Symbol which is different from the current locale?

Viewed 287

I have an app which supports both English and Japanese locales. There, I am creating a button and set an UIImage to it, which uses a SF Symbol.

let image = UIImage(systemName: "textbox")!.withConfiguration(UIImage.SymbolConfiguration(pointSize: 30, weight: .regular))
button.setImage(image, for: .normal)

Now for English and Japanese locales, the button looks like below. enter image description here

I have a requirement to stop localisation happening for the image of this specific button. For both locales, I want the SF Symbol now appears for English to be shown in the button. Is there a way to achieve this with SF Symbols ?

2 Answers

It seems like the only way to force a specific language for an SF Symbol is by appending a language code, so in case of textbox:

UIImage(systemName: "textbox")
UIImage(systemName: "textbox.ar")
UIImage(systemName: "textbox.he")
UIImage(systemName: "textbox.hi")
UIImage(systemName: "textbox.ja")
UIImage(systemName: "textbox.ko")
UIImage(systemName: "textbox.th")
UIImage(systemName: "textbox.zh")
UIImage(systemName: "textbox.zh.traditional")

However, this won't allow you to force the English version, but only non-English ones. You are probably out of luck when loading SF Symbols through Apple's APIs. I would go for Joakim Danielson's approach and try to export the default icon.

If someone wants to do this for any locale except English, then the answer from @wakel would be the better option.

For locale English, as @JoakimDanielson suggested in a comment, I have done this by downloading SF Symbols app and by exporting the required SF Symbol as a custom symbol template

SF Symbols app -> File -> Export Custom Symbol Template

This custom symbol is without any locales by default, which can be added to Assets of the project. Once it has added, you can use it as any other image asset you added using UIImage(named:)

let image = UIImage(named: "textbox")!.withConfiguration(UIImage.SymbolConfiguration(pointSize: 30, weight: .regular))
button.setImage(image, for: .normal)

The official Apple documentation for exporting symbols from SF Symbols app is here https://developer.apple.com/documentation/uikit/uiimage/creating_custom_symbol_images_for_your_app

Related