Created
February 3, 2019 06:01
-
-
Save laevandus/54a29589aff7ed357ce4afb175bfe867 to your computer and use it in GitHub Desktop.
This file contains 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 item = content[indexPath.item] | |
switch item { | |
case .iconAction: | |
let action = UIContextualAction(style: .normal, title: item.rawValue, handler: { [weak self] (action, view, block) in | |
self?.showAlert(item.rawValue) | |
}) | |
action.backgroundColor = UIColor(hue: 0.11, saturation: 0.56, brightness: 0.48, alpha: 1.0) | |
action.image = UIImage(named: "Icon") | |
return UISwipeActionsConfiguration(actions: [action]) | |
case .multipleTrailingActions: | |
let action1 = UIContextualAction(style: .normal, title: "Action1", handler: { [weak self] (action, view, block) in | |
self?.showAlert("Action1") | |
}) | |
action1.backgroundColor = UIColor(hue: 0.56, saturation: 0.56, brightness: 0.55, alpha: 1.0) | |
let action2 = UIContextualAction(style: .normal, title: "Action2", handler: { [weak self] (action, view, block) in | |
self?.showAlert("Action2") | |
}) | |
action2.backgroundColor = UIColor(hue: 0.35, saturation: 0.33, brightness: 0.55, alpha: 1.0) | |
return UISwipeActionsConfiguration(actions: [action1, action2]) | |
case .trailingAction: | |
let action = UIContextualAction(style: .normal, title: item.rawValue, handler: { [weak self] (action, view, block) in | |
self?.showAlert(item.rawValue) | |
}) | |
return UISwipeActionsConfiguration(actions: [action]) | |
case .trailingDestructiveAction: | |
let action = UIContextualAction(style: .destructive, title: item.rawValue, handler: { [weak self] (action, view, block) in | |
self?.showAlert(item.rawValue) | |
}) | |
return UISwipeActionsConfiguration(actions: [action]) | |
case .trailingTableViewDefaultAction: | |
return nil | |
case .leadingAction, .leadingDestructiveAction, .tooManyLeadingActions: | |
return UISwipeActionsConfiguration(actions: []) // when returning nil, default actions are shown | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment