[英]UITableViewCell swipe action
I am creating UITableView with swipe action.我正在使用滑动操作创建 UITableView。 I have read many articles.
我已经阅读了很多文章。 I can do edit and delete action in the TableView.
我可以在 TableView 中进行编辑和删除操作。 But could not create a design like i posted here.
但无法创建像我在这里发布的设计。 I need increase decrease button action.
我需要增加减少按钮动作。
I have given small piece of sample code below.我在下面给出了一小段示例代码。
func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
{
let accept = UIContextualAction(style: .normal, title: "accept") { (action, view, nil) in
print("accepted")
}
accept.backgroundColor = .lightGray
accept.image = UIImage(named: "edit")
return UISwipeActionsConfiguration(actions: [accept])
}
Help me to achieve this.帮助我实现这一目标。 Thanks in advance.
提前致谢。
Try this method, hope it helps a bit..试试这个方法,希望对你有帮助。。
func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let increaseAction = UIContextualAction(style: .normal, title: "Increase") { (action, view, completion) in
// Perform your addition here..
completion(true)
}
let decreaseAction = UIContextualAction(style: .normal, title: "Decrease") { (action, view, completion) in
// Perform your subtraction here..
completion(true)
}
// set images to buttons..
increaseAction.image = UIImage(named: "plusImage.png")
decreaseAction.image = UIImage(named: "minusImage.png")
// Just incase if want to change the backgroundColor..
increaseAction.backgroundColor = UIColor.red
decreaseAction.backgroundColor = UIColor.green
return UISwipeActionsConfiguration(actions: [increaseAction, decreaseAction])
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.