Skip to content

Instantly share code, notes, and snippets.

@SunXiaoShan
Created April 22, 2020 03:51
Show Gist options
  • Save SunXiaoShan/a7b8126abee80c385617f18833345084 to your computer and use it in GitHub Desktop.
Save SunXiaoShan/a7b8126abee80c385617f18833345084 to your computer and use it in GitHub Desktop.
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "DragDrogCollectionViewCell", for: indexPath) as! DragDrogCollectionViewCell
let index = indexPath.section * ViewController.columnCount + indexPath.row
cell.backgroundColor = UIColor.clear
cell.label.text = ""
if (index < cellDataList.count) {
cell.backgroundColor = UIColor.yellow
cell.label.text = String(cellDataList[index])
}
return cell
}
func collectionView(_ collectionView: UICollectionView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
let dataIndex = getCollectionViewColumnMaxCount() * indexPath.section + indexPath.row
guard (dataIndex < self.cellDataList.count) else {
return []
}
let attributedString = String(indexPath.item)
let dragItem = UIDragItem(itemProvider: NSItemProvider(object: attributedString as NSItemProviderWriting))
dragItem.localObject = attributedString
return [dragItem]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment