SwiftUI - 无法更改图像图标的颜色 [英] SwiftUI - Unable to change color of Image icon
本文介绍了SwiftUI - 无法更改图像图标的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试构建自己的自定义标签栏视图,但在构建自定义按钮时,我无法更改 Image() 的颜色.
I am trying to build my own custom tabbar view, while building my custom buttons I am unable to change the color of Image().
struct TabBarButton: View {
let title: String
let icon: String
var body: some View {
return GeometryReader{ geometry in
VStack {
Image(self.icon)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: geometry.size.width/2, height: CGFloat(25))
.foregroundColor(.white)
Text(self.title)
.font(.system(size: 8))
.foregroundColor(Color.white)
}
}
}
}
我尝试过 foregroundColor(Color.white)、accentColor(Color.white) 和一些不同的颜色乘数.除了默认的黑色之外,是否有其他颜色没有其他原因?简单的修复只是获得白色图标,但希望我现在可以解决这个问题.
I have tried foregroundColor(Color.white), accentColor(Color.white), and some different color multipliers. Is there a reason the color isn't anything other than default black? Easy fix is just to get white icons but was hoping I could solve this for now.
推荐答案
我不确定你想达到什么目的,但可能你只需要模板渲染模式,比如
I'm not sure what are you trying to to achieve, but probably you just need template rendering mode, like
Image(self.icon)
.renderingMode(.template)
.foregroundColor(.white)
这篇关于SwiftUI - 无法更改图像图标的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文