8

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 ?

SamB
  • 1,560
  • 1
  • 13
  • 19
  • 2
    One possible solution you could try is to export the symbol from the SF Symbol app and add it as an asset to your project. You should check that there is no copyright issues or similar with doing this. – Joakim Danielson Aug 31 '21 at 12:00
  • @JoakimDanielson I checked the Apple documentation and we are allowed to export a SF Symbol then customize it and use. Thanks for the suggestion. I'll go with this approach. Documentation -> https://developer.apple.com/documentation/uikit/uiimage/creating_custom_symbol_images_for_your_app – SamB Sep 01 '21 at 02:13

2 Answers2

6

2023 Update

On iOS 17+ it is now possible to specify a Locale when retrieving an SF symbol:

UIImage(systemName: "textbox", withConfiguration: .init(locale: .init(identifier: "en-US")))

Original answer

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.

wakel
  • 336
  • 2
  • 7
  • Didn't know that we could append locale to the SF symbols. Too bad this cannot be done for English though :) – SamB Sep 01 '21 at 02:09
  • Why can't this be done for English? Does `"textbox.en"` not work? BTW - the SF Symbol has been renamed to "character.textbox" as of iOS 14.5. – HangarRash Jul 13 '23 at 17:10
  • @HangarRash Exactly, when trying to use `textbox.en` no SF Symbol can be found. – wakel Jul 14 '23 at 07:53
3

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

SamB
  • 1,560
  • 1
  • 13
  • 19