如何在Swift中的滑动操作中更改UITableviewCell背景颜色?

时间:2018-05-31 11:45:08

标签: ios swift

---------------------这是我的代码------------------- -

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {

        let important = importantAction(at: indexPath)
        //let delete = deleteAction(at: indexPath)

        return UISwipeActionsConfiguration(actions: [important])

    }

    @available(iOS 11.0, *)
    func importantAction(at indexPath: IndexPath) -> UIContextualAction
    {


        let action = UIContextualAction(style: .normal, title: nil) { (action, view, completion) in


            completion(true)
        }
        action.image = #imageLiteral(resourceName: "checked_wht")
        action.backgroundColor = UIColor.green

        return action
    }

1 个答案:

答案 0 :(得分:0)

试试这段代码

@available(iOS 11.0, *)
func importantAction(at indexPath: IndexPath) -> UIContextualAction
{
    let action = UIContextualAction(style: .normal, title: nil) { (action, view, completion) in
        completion(true)
        let indexPath = IndexPath(item: indexPath.row, section: 0)
        self.tableView.reloadRows(at: [indexPath], with: .top)
    }
    let cell:UITableViewCell = (tableView.cellForRow(at: IndexPath(row: indexPath.row, section: 0)))!
    cell.backgroundColor = UIColor.red
    action.backgroundColor = UIColor.green

    return action
}
相关问题