swiftui

SwiftUI: Inline image size


I am adding inline image (SF symbol) into Text with .appendInterpolation like this:

Text("Hello \(Image(systemName: "swift"))")

This works great, but I would like to change the symbol size. How can I do it?

I tried

Text("Hello \(Image(systemName: "swift").font(.system(size: 12)))")

but I only get this error: 'appendInterpolation' is unavailable: Unsupported type for interpolation, see LocalizedStringKey.StringInterpolation for supported types.


Solution

  • How about using plus operator for Text?

    Text("Hello ")
    +
    Text(Image(systemName: "swift"))
        .font(.title.bold())
    +
    Text(" Swift!")