[英]SwiftUI - How to change the color of a custom SF symbol in a Text View?
所以,我在 SwiftUI 視圖中有一個文本,其中有一個自定義 SF 符號:
Text("This is some text with a \(Image(uiImage: UIImage(named: "customSFSymbol")!)) symbol.")
問題如下:
我想讓所有視圖都變成白色,但是當我將.foregroundColor(Color.white)
添加到視圖時,SF 符號保持黑色。
你可以在這里看到它現在的樣子
提前感謝您的幫助!
您可以簡單地將.renderingMode(.template)
添加到Image
Text("This is some text with a \(Image(uiImage: UIImage(named: "customSFSymbol")!).renderingMode(.template)) symbol.")
你可以這樣使用
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)
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.