diff --git a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift index 6340d613..59bcbbd4 100644 --- a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift +++ b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift @@ -62,8 +62,12 @@ public class RadioSwatchGroupBase.self, forCellWithReuseIdentifier: "collectionViewCell") } @@ -105,15 +110,45 @@ public class RadioSwatchGroupBase 0 else { + collectionViewHeight?.constant = 0 + return + } + + // Calculate the height + let swatchesInRow = floor(CGFloat(collectionView.bounds.width/(cellSize + itemSpacing))) + let numberOfRows = ceil(CGFloat(swatches.count)/swatchesInRow) + let height = (numberOfRows * cellSize) + (itemSpacing * (numberOfRows-1)) + + collectionViewHeight?.constant = CGFloat(height) + } + open override func shouldUpdateView(viewModel: ModelType) -> Bool { return viewModel != model }