Skip to content

Instantly share code, notes, and snippets.

@KrauserHuang
Created March 7, 2021 10:37
Show Gist options
  • Save KrauserHuang/ee62602ffd2e1ff9948517633d54dad8 to your computer and use it in GitHub Desktop.
Save KrauserHuang/ee62602ffd2e1ff9948517633d54dad8 to your computer and use it in GitHub Desktop.
// 建立UICollectionView
let myCollectionView = UICollectionView(frame: CGRect(x: 0, y: 20, width: fullScreenSize.width, height: fullScreenSize.height - 20), collectionViewLayout: layout)
// 註冊cell來重複利用
myCollectionView.register(MyCollectionViewCell.self, forCellWithReuseIdentifier: "Cell")
// 註冊section的header/footer來重複使用
myCollectionView.register(UICollectionReusableView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "Header")
myCollectionView.register(UICollectionReusableView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: "Footer")
// 設置委任對象
myCollectionView.delegate = self
myCollectionView.dataSource = self
view.addSubview(myCollectionView)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment