diff --git a/CollectionViewShelfLayout/CollectionViewShelfLayout.swift b/CollectionViewShelfLayout/CollectionViewShelfLayout.swift index f27138b..d09e667 100644 --- a/CollectionViewShelfLayout/CollectionViewShelfLayout.swift +++ b/CollectionViewShelfLayout/CollectionViewShelfLayout.swift @@ -110,7 +110,9 @@ open class CollectionViewShelfLayout: UICollectionViewLayout { if let headerView = headerView { headerViewLayoutAttributes = CollectionViewShelfLayoutHeaderFooterViewLayoutAttributes(forDecorationViewOfKind: ShelfElementKindCollectionHeader, with: IndexPath(index: 0)) headerViewLayoutAttributes?.view = headerView - let headerViewSize = headerView.systemLayoutSizeFitting(CGSize(width: collectionViewWidth, height: 0.0), withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel) + //let headerViewSize = headerView.systemLayoutSizeFitting(CGSize(width: collectionViewWidth, height: 0.0), withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel) + let targetSize = CGSize(width: collectionViewWidth, height: 0.0) + let headerViewSize = headerView.systemLayoutSizeFitting(targetSize, withHorizontalFittingPriority: UILayoutPriorityRequired, verticalFittingPriority: UILayoutPriorityFittingSizeLevel) headerViewLayoutAttributes?.size = headerViewSize headerViewLayoutAttributes?.frame = CGRect(origin: CGPoint(x: collectionBounds.minX, y: currentY), size: headerViewSize) currentY += headerViewSize.height @@ -206,7 +208,7 @@ open class CollectionViewShelfLayout: UICollectionViewLayout { if let footerView = footerView { footerViewLayoutAttributes = CollectionViewShelfLayoutHeaderFooterViewLayoutAttributes(forDecorationViewOfKind: ShelfElementKindCollectionFooter, with: IndexPath(index: 0)) footerViewLayoutAttributes?.view = footerView - let footerViewSize = footerView.systemLayoutSizeFitting(CGSize(width: collectionViewWidth, height: 0.0), withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel) + let footerViewSize = footerView.systemLayoutSizeFitting(CGSize(width: collectionViewWidth, height: 0.0), withHorizontalFittingPriority: UILayoutPriorityRequired, verticalFittingPriority: UILayoutPriorityFittingSizeLevel) footerViewLayoutAttributes?.size = footerViewSize footerViewLayoutAttributes?.frame = CGRect(origin: CGPoint(x: collectionBounds.minX, y: currentY), size: footerViewSize) currentY += footerViewSize.height