Created
April 22, 2020 01:42
-
-
Save SunXiaoShan/6cad03e2050e8fd509f108b7cc32492c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class ViewController: UIViewController { | |
@IBOutlet weak var collectionView: UICollectionView! | |
// create a collection view data list | |
var cellDataList:[Any] = [1, 1, 1, 1, 1, 1, 1] | |
// custom ui layout for collection view | |
let columnLayout = ColumnFlowLayout( | |
cellsPerRow: 5, | |
minimumInteritemSpacing: 10, | |
minimumLineSpacing: 10, | |
sectionInset: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10) | |
) | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view. | |
setupCollectionView() | |
} | |
func setupCollectionView() { | |
// Set up the new layout | |
self.collectionView.collectionViewLayout = columnLayout | |
self.collectionView.dataSource = self | |
} | |
} | |
extension ViewController: UICollectionViewDataSource { | |
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | |
return self.cellDataList.count | |
} | |
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { | |
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "DragDrogCollectionViewCell", for: indexPath) as! DragDrogCollectionViewCell | |
cell.backgroundColor = UIColor.yellow | |
return cell | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment