Created
February 18, 2021 12:57
-
-
Save 10Macit/5c3df022100b2273fb32f841950d3f0f 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 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