Skip to content

Instantly share code, notes, and snippets.

@SunXiaoShan
Created April 22, 2020 02:23
Show Gist options
  • Save SunXiaoShan/0f4d7fee1a1cc7d8373a2a82e6285de8 to your computer and use it in GitHub Desktop.
Save SunXiaoShan/0f4d7fee1a1cc7d8373a2a82e6285de8 to your computer and use it in GitHub Desktop.
func setupCollectionView() {
self.collectionView.collectionViewLayout = columnLayout
self.collectionView.dataSource = self
self.collectionView.dragDelegate = self
self.collectionView.dragInteractionEnabled = true
}
extension ViewController: UICollectionViewDragDelegate {
func collectionView(_ collectionView: UICollectionView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
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