【发布时间】:2020-10-09 03:45:49
【问题描述】:
我们如何为 WKWebView 中的链接设置自定义上下文菜单?
您可以通过执行以下操作在项目上设置上下文菜单:
let interaction = UIContextMenuInteraction(delegate: self)
someItem.addInteraction(interaction)
并添加 UIContextMenuInteractionDelegate 委托:
func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
let configuration = UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { (_) -> UIMenu? in
let shareAction = UIAction(title: "Send to Friend", image: UIImage(systemName: "square.and.arrow.up")) { _ in
// Pressed
}
let menu = UIMenu(title: "", children: [shareAction])
return menu
}
return configuration
}
当用户按住 WKWebView 中的链接时,如何使用自定义上下文菜单?
【问题讨论】: