Skip to content

Instantly share code, notes, and snippets.

@10Macit
Created February 18, 2021 12:57
Show Gist options
  • Save 10Macit/5c3df022100b2273fb32f841950d3f0f to your computer and use it in GitHub Desktop.
Save 10Macit/5c3df022100b2273fb32f841950d3f0f to your computer and use it in GitHub Desktop.
class SelfSizingCollectionView: UICollectionView {
override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
super.init(frame: frame, collectionViewLayout: layout)
commonInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}
private func commonInit() {
isScrollEnabled = false
}
override var contentSize: CGSize {
didSet {
invalidateIntrinsicContentSize()
}
}
override func reloadData() {
super.reloadData()
invalidateIntrinsicContentSize()
}
override var intrinsicContentSize: CGSize {
layoutIfNeeded()
return contentSize
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment