有没有办法更改swiftui中sf符号图标的笔划/填充颜色?
我正在寻找一种方法来更改swiftui中sf符号图标的笔划/填充颜色 我尝试了有没有办法更改swiftui中sf符号图标的笔划/填充颜色?,swiftui,sf-symbols,Swiftui,Sf Symbols,我正在寻找一种方法来更改swiftui中sf符号图标的笔划/填充颜色 我尝试了.background(Color.red)但这只是改变了整个图标的背景(实际图标本身没有变化),这意味着我还尝试了.foregroundColor(Color.red),它对图标没有任何影响 内容视图的内容如下 var body: some View { Image(systemName: "person.circle").foregroundColor(.red) } 是的,有: var body: s
.background(Color.red)
但这只是改变了整个图标的背景(实际图标本身没有变化),这意味着我还尝试了.foregroundColor(Color.red)
,它对图标没有任何影响
内容视图的内容如下
var body: some View {
Image(systemName: "person.circle").foregroundColor(.red)
}
是的,有:
var body: some View {
Image(systemName: "person.circle").accentColor(.red)
}
您可以使用
foregroundColor(\uColor:color?)
以下代码:
Image(systemName: "flame.fill").foregroundColor(.red)
应产生以下结果:
下面是完整的SwiftUI视图代码
struct Icon : View {
var body: some View {
HStack{
Image(systemName: "flame.fill")
.foregroundColor(.red)
Image(systemName: "flame")
.foregroundColor(.red)
}
.padding()
}
}
只需改变颜色。这为我做到了。单击我以这将以红色绘制图标的背景,以蓝色绘制线条:
Image(systemName: "person.circle")
.foregroundColor(Color.red)
.background(Color.blue)
.frame(width: size, height: self, alignment: .center)
.clipShape(Circle())
如果没有clipShape,圆圈后面的矩形中将有蓝色的角。iOS 15
在SwiftUI 3/iOS 15中,我们可以使用foregroundStyle
来定制更多SF符号:
Image(systemName: "cloud.sun.bolt")
.foregroundStyle(.gray, .blue)
更多信息,请访问:
图像(系统名:“person.circle”).foregroundColor(.red)
为我在一个圆圈中画一个红色的人。它为你画了什么?对我来说,它仍然是一个黑色的图标。它可能只是一个xcode错误。。。至少我希望如此。请发布一个小的、独立的测试。创建一个新的SwiftUI项目并修改默认的ContentView
,以演示该问题。然后将ContentView
的定义复制到您的问题中。已编辑!但是,对于一个自包含的项目,仍然是黑色的。您是在运行代码还是在使用预览?对我来说,预览将图标显示为黑色,但运行它将正确地更改颜色foregroundColor
帮我搞定了。另请注意,如果使用图像(uiImage:uiImage(“flame.fill”)
SFSymbol.fill
或。现在根据包含的视图自动选择轮廓
变体,则前景颜色
对图像没有影响。e、 g.在Mac上的选项卡中。Mac和iOS选项卡视图不同时使用.fill
。这在早期的测试版中有效。我认为目前,正确的方法是使用.foregroundColor(.red)。
Image(systemName: "cloud.sun.bolt")
.foregroundStyle(.gray, .blue)