Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView - How to change the background color of cell during drag drop?

I'm implementing drag and drop between two UITableView's. When dragging an item over tableView, the tableView automatically displays the space where the new cell will be inserted. I'd like to highlight that space by changing the background color.

Currently, the space for the new cell shows in white. If I change the background color of UITableView, then the space reflects the corresponding background color. However, I do not want to change the background color for the tableView.

Can someone help on how I can achieve it?

Here's a screenshot of the functionality that I'm looking for.

see screenshot

Thanks, Felix.J

like image 449
Felix Marianayagam Avatar asked Mar 19 '18 08:03

Felix Marianayagam


1 Answers

Depending on if you're trying to set the background of the future location of the cell or the cell itself, you can alter the background and add effects to the drag cell by calling the dragPreviewParametersForRowAt function. For example:

func tableView(_ tableView: UITableView, dragPreviewParametersForRowAt indexPath: IndexPath) -> UIDragPreviewParameters? {

        let param = UIDragPreviewParameters()
        param.backgroundColor = .clear
        return param
}

would remove the default white backdrop while a cell is being dragged within a table view.

like image 160
Kyle Beard Avatar answered Oct 21 '22 02:10

Kyle Beard