尝试改变UIAction中的图标颜色,但改变色调似乎根本不起作用。有什么想法吗?
let imageView = UIImage(systemName: "eye")!
.withTintColor(.red, renderingMode: .alwaysTemplate)下面的源代码来自苹果“向菜单栏和用户界面添加菜单和快捷方式”示例,只有imageView是新元素。
func contextMenuActions() -> [UIMenuElement] {
let imageView = UIImage(systemName: "eye")?.withTintColor(.red, renderingMode: .alwaysTemplate)
// Actions for the contextual menu, here you apply two actions.
let copyAction = UIAction(title: NSLocalizedString("CopyTitle", comment: ""),
image: imageView,
identifier: UIAction.Identifier(rawValue: "com.example.apple-samplecode.menus.copy")) { action in
// Perform the "Copy" action, by copying the detail label string.
if let content = self.detailItem?.description {
UIPasteboard.general.string = content
}
}

发布于 2020-11-07 12:30:52
您需要使用呈现模式.alwaysOriginal,因为在内部它们使用UIImageView,它为所有模板映像应用自己的tintColor。
所以制造
func contextMenuActions() -> [UIMenuElement] {
let imageView = UIImage(systemName: "eye")?.withTintColor(.red,
renderingMode: .alwaysOriginal) // << here !!给出

用Xcode 12.1测试
https://stackoverflow.com/questions/64714923
复制相似问题