Search code examples
iosswiftsf-symbols

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


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 ?


Solution

  • 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