2

So, I have a Text in a SwiftUI view that has a custom SF symbol in it:

Text("This is some text with a   \(Image(uiImage: UIImage(named: "customSFSymbol")!))  symbol.")

The problem is the following:

I want to make all that view white, but when I add the .foregroundColor(Color.white) to the view, the SF Symbol stays in a black color.

You can see how it looks right now here

Thanks for your help in advance!

AnderCover
  • 2,488
  • 3
  • 23
  • 42
LeonardoXUI
  • 411
  • 3
  • 10

2 Answers2

2

You can simply add .renderingMode(.template) to the Image

Text("This is some text with a   \(Image(uiImage: UIImage(named: "customSFSymbol")!).renderingMode(.template))  symbol.")
cedricbahirwe
  • 1,274
  • 4
  • 15
0

You can use like this

struct ContentView: View {
    var body: some View {
        Text("This is some text with a ").foregroundColor(Color.red) + imageText + Text("symbol.").foregroundColor(Color.red)
    }
    
    @ViewBuilder
    var imageText: Text {
        Text("\(Image(systemName: "square.and.pencil"))")
            .foregroundColor(Color.blue)
    }
}
blue symbol within red text
aheze
  • 24,434
  • 8
  • 68
  • 125
Raja Kishan
  • 16,767
  • 2
  • 26
  • 52