Skip to content

Instantly share code, notes, and snippets.

@IsaAliev
Created April 10, 2021 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IsaAliev/031922126fc14a0494c70d4ff317452b to your computer and use it in GitHub Desktop.
Save IsaAliev/031922126fc14a0494c70d4ff317452b to your computer and use it in GitHub Desktop.
class TestCell: UICollectionViewCell, BoundingWidthAdoptable {
private var boundingWidth: CGFloat = 0
func adoptBoundingWidth(_ width: CGFloat) {
boundingWidth = width
}
override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
let attributes = super.preferredLayoutAttributesFitting(layoutAttributes)
attributes.size = .init(width: boundingWidth, height: 100)
return attributes
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment