Created
April 22, 2020 03:51
-
-
Save SunXiaoShan/a7b8126abee80c385617f18833345084 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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