【发布时间】:2020-11-06 12:44:54
【问题描述】:
尝试在 UIAction 中更改图标颜色,但更改色调似乎根本不起作用。有什么想法吗?
let imageView = UIImage(systemName: "eye")!
.withTintColor(.red, renderingMode: .alwaysTemplate)
下面的源代码来自苹果"Adding Menus and Shortcuts to the Menu Bar and User Interface"的例子,只有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
}
}
【问题讨论】: