Merge branch 'feature/buttonGroupUpdate' into 'develop'

moved out methods to constants

See merge request BPHV_MIPS/vds_ios!18
This commit is contained in:
Bruce, Matt R 2022-12-01 21:32:16 +00:00
commit 0ab60733eb
4 changed files with 215 additions and 188 deletions

View File

@ -62,6 +62,7 @@
EAB5FEED2927E1B200998C17 /* ButtonGroupPositionLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEEC2927E1B200998C17 /* ButtonGroupPositionLayout.swift */; }; EAB5FEED2927E1B200998C17 /* ButtonGroupPositionLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEEC2927E1B200998C17 /* ButtonGroupPositionLayout.swift */; };
EAB5FEF12927F4AA00998C17 /* SelfSizingCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEF02927F4AA00998C17 /* SelfSizingCollectionView.swift */; }; EAB5FEF12927F4AA00998C17 /* SelfSizingCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEF02927F4AA00998C17 /* SelfSizingCollectionView.swift */; };
EAB5FEF5292D371F00998C17 /* ButtonBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEF4292D371F00998C17 /* ButtonBase.swift */; }; EAB5FEF5292D371F00998C17 /* ButtonBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEF4292D371F00998C17 /* ButtonBase.swift */; };
EAB5FEF829393A7200998C17 /* ButtonGroupConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEF729393A7200998C17 /* ButtonGroupConstants.swift */; };
EAC9257D29119B5400091998 /* TextLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAC9257C29119B5400091998 /* TextLink.swift */; }; EAC9257D29119B5400091998 /* TextLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAC9257C29119B5400091998 /* TextLink.swift */; };
EAC925832911B35400091998 /* TextLinkCaret.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAC925822911B35300091998 /* TextLinkCaret.swift */; }; EAC925832911B35400091998 /* TextLinkCaret.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAC925822911B35300091998 /* TextLinkCaret.swift */; };
EAC925842911C63100091998 /* Colorable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA5EEDF28F49DB3003B3210 /* Colorable.swift */; }; EAC925842911C63100091998 /* Colorable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA5EEDF28F49DB3003B3210 /* Colorable.swift */; };
@ -155,6 +156,7 @@
EAB5FEEC2927E1B200998C17 /* ButtonGroupPositionLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonGroupPositionLayout.swift; sourceTree = "<group>"; }; EAB5FEEC2927E1B200998C17 /* ButtonGroupPositionLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonGroupPositionLayout.swift; sourceTree = "<group>"; };
EAB5FEF02927F4AA00998C17 /* SelfSizingCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelfSizingCollectionView.swift; sourceTree = "<group>"; }; EAB5FEF02927F4AA00998C17 /* SelfSizingCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelfSizingCollectionView.swift; sourceTree = "<group>"; };
EAB5FEF4292D371F00998C17 /* ButtonBase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonBase.swift; sourceTree = "<group>"; }; EAB5FEF4292D371F00998C17 /* ButtonBase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonBase.swift; sourceTree = "<group>"; };
EAB5FEF729393A7200998C17 /* ButtonGroupConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonGroupConstants.swift; sourceTree = "<group>"; };
EAC9257C29119B5400091998 /* TextLink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextLink.swift; sourceTree = "<group>"; }; EAC9257C29119B5400091998 /* TextLink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextLink.swift; sourceTree = "<group>"; };
EAC925822911B35300091998 /* TextLinkCaret.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextLinkCaret.swift; sourceTree = "<group>"; }; EAC925822911B35300091998 /* TextLinkCaret.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextLinkCaret.swift; sourceTree = "<group>"; };
EAC925872911C9DE00091998 /* TextEntryField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextEntryField.swift; sourceTree = "<group>"; }; EAC925872911C9DE00091998 /* TextEntryField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextEntryField.swift; sourceTree = "<group>"; };
@ -226,6 +228,7 @@
children = ( children = (
EA0FC2C52914222900DF80B4 /* ButtonGroup.swift */, EA0FC2C52914222900DF80B4 /* ButtonGroup.swift */,
EAB5FEEC2927E1B200998C17 /* ButtonGroupPositionLayout.swift */, EAB5FEEC2927E1B200998C17 /* ButtonGroupPositionLayout.swift */,
EAB5FEF729393A7200998C17 /* ButtonGroupConstants.swift */,
); );
path = ButtonGroup; path = ButtonGroup;
sourceTree = "<group>"; sourceTree = "<group>";
@ -680,6 +683,7 @@
EAB1D2CF28ABEF2B00DAE764 /* Typography.swift in Sources */, EAB1D2CF28ABEF2B00DAE764 /* Typography.swift in Sources */,
EAF7F09A2899B17200B287F5 /* CATransaction.swift in Sources */, EAF7F09A2899B17200B287F5 /* CATransaction.swift in Sources */,
EAF7F0A2289AFB3900B287F5 /* Errorable.swift in Sources */, EAF7F0A2289AFB3900B287F5 /* Errorable.swift in Sources */,
EAB5FEF829393A7200998C17 /* ButtonGroupConstants.swift in Sources */,
EA3361AF288B26310071C351 /* FormFieldable.swift in Sources */, EA3361AF288B26310071C351 /* FormFieldable.swift in Sources */,
EA89201528B56CF4006B9984 /* RadioBoxGroup.swift in Sources */, EA89201528B56CF4006B9984 /* RadioBoxGroup.swift in Sources */,
EAF7F09E289AAEC000B287F5 /* Constants.swift in Sources */, EAF7F09E289AAEC000B287F5 /* Constants.swift in Sources */,

View File

@ -121,6 +121,7 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega
open override func updateView() { open override func updateView() {
super.updateView() super.updateView()
positionLayout.position = buttonPosition positionLayout.position = buttonPosition
positionLayout.rowQuantity = rowQuantity
collectionView.reloadData() collectionView.reloadData()
} }
@ -169,8 +170,6 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega
public func collectionView(_ collectionView: UICollectionView, buttonableAtIndexPath indexPath: IndexPath) -> Buttonable { public func collectionView(_ collectionView: UICollectionView, buttonableAtIndexPath indexPath: IndexPath) -> Buttonable {
buttons[indexPath.row] buttons[indexPath.row]
} }
public func collectionView(_ collectionView: UICollectionView, insetsForItemsInSection section: Int) -> UIEdgeInsets {
UIEdgeInsets.zero
}
} }

View File

@ -0,0 +1,130 @@
//
// ButtonGroupConstants.swift
// VDS
//
// Created by Matt Bruce on 12/1/22.
//
import Foundation
struct ButtonGroupConstants {
static let rowSpacingButton = 12.0
static let rowSpacingTextLink = 12.0
static func getHorizontalSpacing(for primary: Buttonable, neighboring: Buttonable) -> CGFloat {
let defaultSpace = 12.0
//large button
if let button = primary as? Button, button.size == .large {
if let neighboringButton = neighboring as? Button, neighboringButton.size == .large {
return 12.0
} else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .large {
return 16.0
} else if let _ = neighboring as? TextLinkCaret {
return 24.0
} else {
return defaultSpace
}
}
//large text link
else if let textLink = primary as? TextLink, textLink.size == .large {
if let neighboringButton = neighboring as? Button, neighboringButton.size == .large {
return 16.0
} else if let _ = neighboring as? TextLinkCaret {
return 24.0
} else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .large {
return 16.0
} else {
return defaultSpace
}
}
//text link caret
else if let _ = primary as? TextLinkCaret {
if let _ = neighboring as? TextLinkCaret {
return 24.0
} else {
return defaultSpace
}
}
//small button
else if let button = primary as? Button, button.size == .small {
if let neighboringButton = neighboring as? Button, neighboringButton.size == .small {
return 12.0
} else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .small {
return 16.0
} else {
return defaultSpace
}
}
//small text link
else if let textLink = primary as? TextLink, textLink.size == .small {
if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .small {
return 16.0
} else {
return defaultSpace
}
}
//return defaultSpace
else {
return defaultSpace
}
}
static func getVerticalSpacing(for primary: Buttonable, neighboring: Buttonable) -> CGFloat {
let defaultSpace = 12.0
//large button
if let button = primary as? Button, button.size == .large {
if let neighboringButton = neighboring as? Button, neighboringButton.size == .large {
return 12.0
} else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .large {
return 16.0
} else if let _ = neighboring as? TextLinkCaret {
return 24.0
} else {
return defaultSpace
}
}
//large text link
else if let textLink = primary as? TextLink, textLink.size == .large {
if let neighboringButton = neighboring as? Button, neighboringButton.size == .large {
return 16.0
} else if let _ = neighboring as? TextLinkCaret {
return 24.0
} else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .large {
return 24.0
} else {
return defaultSpace
}
}
//text link caret
else if let _ = primary as? TextLinkCaret {
if let _ = neighboring as? TextLinkCaret {
return 24.0
} else {
return defaultSpace
}
}
//small button
else if let button = primary as? Button, button.size == .small {
if let neighboringButton = neighboring as? Button, neighboringButton.size == .small {
return 12.0
} else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .small {
return 24.0
} else {
return defaultSpace
}
}
//small text link
else if let textLink = primary as? TextLink, textLink.size == .small {
if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .small {
return 32.0
} else {
return defaultSpace
}
}
//return defaultSpace
else {
return defaultSpace
}
}
}

View File

@ -8,23 +8,11 @@
import Foundation import Foundation
import UIKit import UIKit
class ButtonLayoutAttributes: UICollectionViewLayoutAttributes{
var spacing: CGFloat = 0
var isButton: Bool = false
convenience init(spacing: CGFloat,
forCellWith indexPath: IndexPath) {
self.init(forCellWith: indexPath)
self.spacing = spacing
}
}
class ButtonCollectionViewRow { class ButtonCollectionViewRow {
var attributes = [ButtonLayoutAttributes]() var attributes = [ButtonLayoutAttributes]()
var spacing: CGFloat = 0
init() {}
init(spacing: CGFloat) {
self.spacing = spacing
}
func add(attribute: ButtonLayoutAttributes) { func add(attribute: ButtonLayoutAttributes) {
attributes.append(attribute) attributes.append(attribute)
@ -61,9 +49,9 @@ class ButtonCollectionViewRow {
case .left: case .left:
break break
case .center: case .center:
offset = (collectionViewWidth - rowWidth) / 2 offset = (collectionViewWidth - rowWidth) / 2
case .right: case .right:
offset = (collectionViewWidth - rowWidth) offset = (collectionViewWidth - rowWidth)
} }
for attribute in attributes { for attribute in attributes {
@ -80,7 +68,16 @@ public enum ButtonPosition: String, CaseIterable {
protocol ButtongGroupPositionLayoutDelegate: AnyObject { protocol ButtongGroupPositionLayoutDelegate: AnyObject {
func collectionView(_ collectionView: UICollectionView, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize func collectionView(_ collectionView: UICollectionView, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize
func collectionView(_ collectionView: UICollectionView, buttonableAtIndexPath indexPath: IndexPath) -> any Buttonable func collectionView(_ collectionView: UICollectionView, buttonableAtIndexPath indexPath: IndexPath) -> any Buttonable
func collectionView(_ collectionView: UICollectionView, insetsForItemsInSection section: Int) -> UIEdgeInsets }
class ButtonLayoutAttributes: UICollectionViewLayoutAttributes{
var spacing: CGFloat = 0
var isButton: Bool = false
convenience init(spacing: CGFloat,
forCellWith indexPath: IndexPath) {
self.init(forCellWith: indexPath)
self.spacing = spacing
}
} }
class ButtonGroupPositionLayout: UICollectionViewLayout { class ButtonGroupPositionLayout: UICollectionViewLayout {
@ -90,105 +87,119 @@ class ButtonGroupPositionLayout: UICollectionViewLayout {
// Total height of the content. Will be used to configure the scrollview content // Total height of the content. Will be used to configure the scrollview content
var layoutHeight: CGFloat = 0.0 var layoutHeight: CGFloat = 0.0
var position: ButtonPosition = .left var position: ButtonPosition = .left
var rowQuantity: Int = 0
private var itemCache: [ButtonLayoutAttributes] = [] private var itemCache: [ButtonLayoutAttributes] = []
override func prepare() { override func prepare() {
super.prepare() super.prepare()
let rowSpacingButton = 12.0
let rowSpacingTextLink = 12.0
itemCache.removeAll() itemCache.removeAll()
layoutHeight = 0.0 layoutHeight = 0.0
guard let collectionView, let delegate else { guard let collectionView, let delegate else { return }
return
}
var itemSpacing = 0.0
// Variable to track the width of the layout at the current state when the item is being drawn // Variable to track the width of the layout at the current state when the item is being drawn
var layoutWidthIterator: CGFloat = 0.0 var layoutWidthIterator: CGFloat = 0.0
// Only 1 section in the ButtonGroup
let section = 0 let section = 0
// Get the necessary data (if implemented) from the delegates else provide default values
let insets: UIEdgeInsets = delegate.collectionView(collectionView, insetsForItemsInSection: section)
let rowSpacing: CGFloat = rowSpacingButton
// Variables to track individual item width and cumultative height of all items as they are being laid out. // Variables to track individual item width and cumultative height of all items as they are being laid out.
var itemSize: CGSize = .zero var itemSize: CGSize = .zero
layoutHeight += insets.top // get number of buttonables
let totalItems = collectionView.numberOfItems(inSection: section) let totalItems = collectionView.numberOfItems(inSection: section)
//create rows
var rows = [ButtonCollectionViewRow]()
rows.append(ButtonCollectionViewRow())
let collectionViewWidth = collectionView.frame.width
for item in 0..<totalItems { for item in 0..<totalItems {
itemSpacing = 0.0 // start out with no spacing after the item
var itemSpacing = 0.0
// create the indexPath
let indexPath = IndexPath(item: item, section: section) let indexPath = IndexPath(item: item, section: section)
// get the rect size of the buttonable
itemSize = delegate.collectionView(collectionView, sizeForItemAtIndexPath: indexPath) itemSize = delegate.collectionView(collectionView, sizeForItemAtIndexPath: indexPath)
if (layoutWidthIterator + itemSize.width + insets.left + insets.right) > collectionView.frame.width { // determine if the current buttonable will fit in the row
// If the current row width (after this item being laid out) is exceeding the width of the collection view content, put it in the next line let rowItemCount = rows.last?.attributes.count ?? 0
if (layoutWidthIterator + itemSize.width) > collectionViewWidth || (rowQuantity > 0 && rowItemCount == rowQuantity) {
// If the current row width (after this item being laid out) is exceeding
// the width of the collection view content, put it in the next line
layoutWidthIterator = 0.0 layoutWidthIterator = 0.0
layoutHeight += itemSize.height + rowSpacing
// set the spacing of the last item of the current row to 0
rows.last?.attributes.last?.spacing = 0
// add a new row
rows.append(ButtonCollectionViewRow())
} }
// get the buttonable
let itemButtonable = delegate.collectionView(collectionView, buttonableAtIndexPath: indexPath) let itemButtonable = delegate.collectionView(collectionView, buttonableAtIndexPath: indexPath)
// see if there is another item in the array
let nextItem = item + 1 let nextItem = item + 1
// if so, get the buttonable
// and get the spacing based of the
// current buttonable and the next buttonable
if nextItem < totalItems { if nextItem < totalItems {
//get the next buttonable
let neighbor = delegate.collectionView(collectionView, buttonableAtIndexPath: IndexPath(item: nextItem, section: section)) let neighbor = delegate.collectionView(collectionView, buttonableAtIndexPath: IndexPath(item: nextItem, section: section))
itemSpacing = getHorizontalSpacing(for: itemButtonable, neighboring: neighbor)
// get the spacing to go between the current and next buttonable
itemSpacing = ButtonGroupConstants.getHorizontalSpacing(for: itemButtonable, neighboring: neighbor)
} }
let frame = CGRect(x: layoutWidthIterator + insets.left, y: layoutHeight, width: itemSize.width, height: itemSize.height) // create the custom layout attribute
//print(frame)
let attributes = ButtonLayoutAttributes(spacing: itemSpacing, forCellWith: indexPath) let attributes = ButtonLayoutAttributes(spacing: itemSpacing, forCellWith: indexPath)
attributes.frame = frame attributes.frame = CGRect(x: 0, y: 0, width: itemSize.width, height: itemSize.height)
attributes.isButton = isButton(buttonable: itemButtonable) attributes.isButton = isButton(buttonable: itemButtonable)
itemCache.append(attributes)
layoutWidthIterator = layoutWidthIterator + frame.width + itemSpacing // add it to the array
rows.last?.add(attribute: attributes)
// update the current width
// add the current frame width + the found spacing
layoutWidthIterator = layoutWidthIterator + attributes.frame.width + itemSpacing
} }
//print("*******")
layoutHeight += itemSize.height + insets.bottom
layoutWidthIterator = 0.0 layoutWidthIterator = 0.0
// recalculate rows x based off of positions
rows.forEach { $0.layout(for: position, with: collectionViewWidth) }
//Turn into rows and re-calculate // calculate the
var rows = [ButtonCollectionViewRow]() layoutHeight = 0.0
var currentRowY: CGFloat = -1
for attribute in itemCache { // loop through the rows and set
if currentRowY != attribute.frame.midY { // the row y position for each element
currentRowY = attribute.frame.midY // also add to the layoutHeight
rows.append(ButtonCollectionViewRow(spacing: itemSpacing))
}
rows.last?.add(attribute: attribute)
}
//recalculate rows based off of positions
rows.forEach { $0.layout(for: position, with: collectionView.frame.width) }
let rowAttributes = rows.flatMap { $0.attributes }
layoutHeight = insets.top
for item in 0..<rows.count { for item in 0..<rows.count {
let row = rows[item] let row = rows[item]
var rowSpacing = 0.0 var rowSpacing = 0.0
if item > 0 && item < rows.count {
rowSpacing = row.hasButtons ? rowSpacingButton : rowSpacingTextLink
}
if item > 0 { if item > 0 {
rowSpacing = row.hasButtons ? ButtonGroupConstants.rowSpacingButton : ButtonGroupConstants.rowSpacingTextLink
row.rowY = layoutHeight + rowSpacing row.rowY = layoutHeight + rowSpacing
layoutHeight += rowSpacing layoutHeight += rowSpacing
} }
layoutHeight += row.rowHeight layoutHeight += row.rowHeight
} }
layoutHeight += insets.bottom
let rowAttributes = rows.flatMap { $0.attributes }
itemCache = rowAttributes itemCache = rowAttributes
} }
@ -200,123 +211,7 @@ class ButtonGroupPositionLayout: UICollectionViewLayout {
return false return false
} }
} }
func getHorizontalSpacing(for primary: Buttonable, neighboring: Buttonable) -> CGFloat {
let defaultSpace = 12.0
//large button
if let button = primary as? Button, button.size == .large {
if let neighboringButton = neighboring as? Button, neighboringButton.size == .large {
return 12.0
} else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .large {
return 16.0
} else if let _ = neighboring as? TextLinkCaret {
return 24.0
} else {
return defaultSpace
}
}
//large text link
else if let textLink = primary as? TextLink, textLink.size == .large {
if let neighboringButton = neighboring as? Button, neighboringButton.size == .large {
return 16.0
} else if let _ = neighboring as? TextLinkCaret {
return 24.0
} else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .large {
return 16.0
} else {
return defaultSpace
}
}
//text link caret
else if let _ = primary as? TextLinkCaret {
if let _ = neighboring as? TextLinkCaret {
return 24.0
} else {
return defaultSpace
}
}
//small button
else if let button = primary as? Button, button.size == .small {
if let neighboringButton = neighboring as? Button, neighboringButton.size == .small {
return 12.0
} else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .small {
return 16.0
} else {
return defaultSpace
}
}
//small text link
else if let textLink = primary as? TextLink, textLink.size == .small {
if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .small {
return 16.0
} else {
return defaultSpace
}
}
//return defaultSpace
else {
return defaultSpace
}
}
func getVerticalSpacing(for primary: Buttonable, neighboring: Buttonable) -> CGFloat {
let defaultSpace = 12.0
//large button
if let button = primary as? Button, button.size == .large {
if let neighboringButton = neighboring as? Button, neighboringButton.size == .large {
return 12.0
} else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .large {
return 16.0
} else if let _ = neighboring as? TextLinkCaret {
return 24.0
} else {
return defaultSpace
}
}
//large text link
else if let textLink = primary as? TextLink, textLink.size == .large {
if let neighboringButton = neighboring as? Button, neighboringButton.size == .large {
return 16.0
} else if let _ = neighboring as? TextLinkCaret {
return 24.0
} else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .large {
return 24.0
} else {
return defaultSpace
}
}
//text link caret
else if let _ = primary as? TextLinkCaret {
if let _ = neighboring as? TextLinkCaret {
return 24.0
} else {
return defaultSpace
}
}
//small button
else if let button = primary as? Button, button.size == .small {
if let neighboringButton = neighboring as? Button, neighboringButton.size == .small {
return 12.0
} else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .small {
return 24.0
} else {
return defaultSpace
}
}
//small text link
else if let textLink = primary as? TextLink, textLink.size == .small {
if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .small {
return 32.0
} else {
return defaultSpace
}
}
//return defaultSpace
else {
return defaultSpace
}
}
override func layoutAttributesForElements(in rect: CGRect)-> [UICollectionViewLayoutAttributes]? { override func layoutAttributesForElements(in rect: CGRect)-> [UICollectionViewLayoutAttributes]? {
var visibleLayoutAttributes: [UICollectionViewLayoutAttributes] = [] var visibleLayoutAttributes: [UICollectionViewLayoutAttributes] = []
@ -341,8 +236,7 @@ class ButtonGroupPositionLayout: UICollectionViewLayout {
guard let collectionView = collectionView else { guard let collectionView = collectionView else {
return 0 return 0
} }
let insets = collectionView.contentInset return collectionView.bounds.width
return collectionView.bounds.width - (insets.left + insets.right)
} }
} }