Last active
September 13, 2021 14:14
-
-
Save trilliwon/0042fa11a4fc6146b0a4422987fa182e to your computer and use it in GitHub Desktop.
uitableview-swipe-actions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { | |
let share = UIContextualAction(style: .normal, title: "Share") { action, view, completion in | |
completion(true) | |
} | |
let delete = UIContextualAction(style: .destructive, title: "Delete") { [weak self] action, view, completion in | |
self?.langs.remove(at: indexPath.row) | |
tableView.deleteRows(at: [indexPath], with: UITableViewRowAnimation.automatic) | |
completion(true) | |
} | |
delete.image = #imageLiteral(resourceName: "trash") | |
return UISwipeActionsConfiguration(actions: [delete, share]) | |
} | |
override func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { | |
let like = UIContextualAction(style: .normal, title: "Like") { [weak self] action, view, completion in | |
guard let `self` = self else { | |
return | |
} | |
self.langs[indexPath.row].liked = !self.langs[indexPath.row].liked | |
completion(true) | |
} | |
like.image = langs[indexPath.row].liked ? #imageLiteral(resourceName: "filledLike") : #imageLiteral(resourceName: "like") | |
like.backgroundColor = UIColor.darkGray | |
return UISwipeActionsConfiguration(actions: [like]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment