请添加图片描述

    
    func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
        //创建“解绑”事件按钮
        let unbind = UIContextualAction(style: .normal, title: "解绑") {
            (action, view, completionHandler) in
            //左滑归位
            completionHandler(true)
        }
        unbind.backgroundColor = .lightGray
        
        //创建“授权”事件按钮
        let authorize = UIContextualAction(style: .normal, title: "授权") {
            (action, view, completionHandler) in
            completionHandler(true)
        }
        authorize.backgroundColor = .gray
        //返回所有的事件按钮 数组的第0个元素在最右边
        let configuration = UISwipeActionsConfiguration(actions: [authorize, unbind])
        return configuration
        
    }

参考博客:
Swift - 自定义tableViewCell滑动事件按钮2(使用iOS11的滑动按钮接口)

更多推荐