diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift index 040ac1b3..353bd4f5 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift @@ -193,6 +193,9 @@ class ButtonGroupPositionLayout: UICollectionViewLayout { // get the rect size of the button itemSize = delegate.collectionView(collectionView, sizeForItemAtIndexPath: indexPath) + // ensure the width is not greater than the collectionViewWidth + itemSize.width = min(itemSize.width, collectionViewWidth) + // determine if the current button will fit in the row let rowItemCount = rows.last?.attributes.count ?? 0 @@ -229,7 +232,7 @@ class ButtonGroupPositionLayout: UICollectionViewLayout { // create the custom layout attribute let attributes = ButtonLayoutAttributes(spacing: itemSpacing, button: itemButtonBase, forCellWith: indexPath) - attributes.frame = CGRect(x: 0, y: 0, width: min(itemSize.width, collectionViewWidth), height: itemSize.height) + attributes.frame = CGRect(x: 0, y: 0, width: itemSize.width, height: itemSize.height) // add it to the array rows.last?.add(attribute: attributes)