Skip to content

Instantly share code, notes, and snippets.

@ycui1
Created January 10, 2020 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ycui1/a1681339935257b655f93ddb43ce3e18 to your computer and use it in GitHub Desktop.
Save ycui1/a1681339935257b655f93ddb43ce3e18 to your computer and use it in GitHub Desktop.
func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
let task = tasks[indexPath.row]
return UIContextMenuConfiguration(identifier: task.id as NSString, previewProvider: nil) { _ in
let blueAction = UIAction(title: "Blue") { _ in }
let redAction = UIAction(title: "Red") { _ in }
let greenAction = UIAction(title: "Green") { _ in }
let purpleAction = UIAction(title: "Purple") { _ in }
let tagActions = UIMenu(title: "Change Tag Color...", children: [blueAction, redAction, greenAction, purpleAction])
let shareAction = UIAction(
title: "Share",
image: UIImage(systemName: "square.and.arrow.up")) { _ in
// share the task
}
let copyAction = UIAction(
title: "Copy",
image: UIImage(systemName: "doc.on.doc")) { _ in
// copy the task content
}
let deleteAction = UIAction(
title: "Delete",
image: UIImage(systemName: "trash"),
attributes: .destructive) { _ in
// delete the task
}
return UIMenu(title: "", children: [tagActions, shareAction, copyAction, deleteAction])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment