Skip to content

Instantly share code, notes, and snippets.

@imnaveensharma
Last active August 6, 2020 12:43
Show Gist options
  • Save imnaveensharma/f6bebf04edc2eed029c8dbb951deafc9 to your computer and use it in GitHub Desktop.
Save imnaveensharma/f6bebf04edc2eed029c8dbb951deafc9 to your computer and use it in GitHub Desktop.
@IBOutlet private weak var collectionView: UICollectionView!
private func registerNibs() {
self.collectionView.register(UINib(nibName: "CollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "CollectionViewCell")
}
// MARK: - Extension :: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout ::
extension MyProfileViewC: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
// MARK: - UICollectionViewDelegate ::
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
}
func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
}
// MARK: - UICollectionViewDataSource ::
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 10
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionViewCell", for: indexPath as IndexPath) as! CollectionViewCell
return cell
}
// MARK: - UICollectionViewDelegateFlowLayout ::
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 15.0
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return 15.0
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 19.0, left: 19.0, bottom: 19.0, right: 19.0)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
var size = CGSize(width: 0, height: 0)
size = CGSize(width: (DeviceWidth-19-15-19)/2, height: 191)
/*
let lay = collectionViewLayout as! UICollectionViewFlowLayout
let widthPerItem = collectionView.frame.width / 2 - lay.minimumInteritemSpacing
size = CGSize(width:widthPerItem, height:191)
*/
return size
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment