Skip to content

Instantly share code, notes, and snippets.

@Athosone
Created April 4, 2017 10:28
Show Gist options
  • Save Athosone/9b0bfabff8ab90ded365f52af857299f to your computer and use it in GitHub Desktop.
Save Athosone/9b0bfabff8ab90ded365f52af857299f to your computer and use it in GitHub Desktop.
Calculate size of uicollectionview
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
guard let dummyCell: OABSubCategoryMenuCell = Bundle.main.loadNibNamed("OABSubCategoryMenuCell", owner: self, options: nil)?.first as? OABSubCategoryMenuCell else {
return CGSize.zero
}
dummyCell.setContent(subCat: self.subCategories[indexPath.row], isSelected: false)
dummyCell.setNeedsLayout()
dummyCell.layoutIfNeeded()
let size: CGSize = dummyCell.contentView.systemLayoutSizeFitting(UILayoutFittingCompressedSize)
return size
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment