在 macOS 中,我想为打开菜单的图像着色,无论我做什么,我只是得到文本彩色图标
Menu {
Button {
} label: {
Text("Some item")
}
} label: {
Image(systemName: "chevron.down.circle.fill")
.foregroundColor(.red)
}
.menuStyle(.borderlessButton)
.menuIndicator(.hidden)
.foregroundColor(.blue)
.fixedSize(horizontal: true, vertical: false)
如何像这样给图标上色
您可以将
foregroundColor
修改器替换为具有两种颜色的 foregroundStyle
,以使用调色板渲染:
Menu {
Button {
} label: {
Text("Some item")
}
} label: {
Image(systemName: "chevron.down.circle.fill")
.foregroundStyle(.white, .green)
}
.symbolRenderingMode(.palette)
将渲染模式更改为调色板。
这将允许您使用
.foregroundStyle
和 .foregroundColor
(尽管现已弃用)来更改图标的颜色。
在这种特殊情况下,您仍然需要应用两种颜色来获得您想要的图标样式。
Menu {
Button {
} label: {
Text("Some item")
}
} label: {
Image(systemName: "chevron.down.circle.fill")
.symbolRenderingMode(.palette)
.foregroundStyle(.white, .green)
}