Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set SF Symbol Color within a Text String (iOS 26)

Tags:

ios

swiftui

ios26

I have a question regarding the deprecation of the plus sign to concatenate strings containing SF symbols.

In iOS 18 I could use the following text in my app: Text(“Tap the keyboard down button (“) + Text(Image(systemName: “keyboard.chevron.compact.down”)).foregroundStyle(Color(.systemBlue)) + Text(“) to close the keyboard.”)

In iOS 26 this gives the warning:

'+' was deprecated in iOS 26.0: Use string interpolation on Text instead: Text("Hello \(name)”)

So upgrading to the new change I tried: Text("Tap the keyboard down button (\(Image(systemName: "keyboard.chevron.compact.down").foregroundStyle(Color(.systemBlue))) to close the keyboard”)

But this gives the warning:

'appendInterpolation' is deprecated: Localized string interpolation produces an unlocalized, debug description for this type of value. Use a type supported by LocalizedStringKey.StringInterpolation or initialize a LocalizedStringResource instead with an interpolated value that conforms to CustomLocalizedStringResourceConvertible.

It appears that I can no longer set the SF symbol color. Am I missing something, or is there another way to set the color of the SF symbol using iOS 26 within a text string?

like image 502
Galen Smith Avatar asked Oct 30 '25 03:10

Galen Smith


1 Answers

It works without compiler warnings if the symbol is created as a separate Text element that is then used as the interpolated string:

let symbol = Text(Image(systemName: "keyboard.chevron.compact.down")).foregroundStyle(.blue)
Text("Tap the keyboard down button (\(symbol)) to close the keyboard")

You can actually do it all in one statement if you really want to:

Text("Tap the keyboard down button (\(Text(Image(systemName: "keyboard.chevron.compact.down")).foregroundStyle(.blue))) to close the keyboard")

If you want to localize the text, %@ can be used as the placeholder for the Text holding the symbol:

"TEXT_WITH_SYMBOL %@" = "Tap the keyboard down button (%@) to close the keyboard";
Text("TEXT_WITH_SYMBOL \(symbol)")

Screenshot

like image 140
Benzy Neez Avatar answered Oct 31 '25 18:10

Benzy Neez