refactored more code
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
7efc0096af
commit
30a4b1e0f7
@ -68,13 +68,10 @@ class ButtonCollectionViewRow {
|
||||
|
||||
//getting available button space since textlinks need their space
|
||||
let buttonsAvailableSpace = collectionViewWidth - nonButtonSpace - totalSpacingBetweenAttributes
|
||||
var maxButtonWidth = buttonsAvailableSpace / buttonCount
|
||||
var buttonCalculatedPercentage: CGFloat = 0.0
|
||||
let buttonEqualSpacing = buttonsAvailableSpace / buttonCount
|
||||
|
||||
// test sizing
|
||||
let testSize = maxButtonWidth * CGFloat(buttonAttributes.count)
|
||||
|
||||
var maxButtonWidth = buttonEqualSpacing //default to equal spacing
|
||||
var buttonCalculatedPercentage: CGFloat = 0.0
|
||||
|
||||
//check to see if you have buttons and there is a percentage
|
||||
if let buttonPercentage, hasButtons, buttonPercentage > 0 {
|
||||
buttonCalculatedPercentage = CGFloat(buttonPercentage / 100.0)
|
||||
@ -83,12 +80,14 @@ class ButtonCollectionViewRow {
|
||||
}
|
||||
|
||||
//resize the buttonAttributes
|
||||
if maxButtonWidth >= Button.Size.large.minimumWidth && !buttonAttributes.isEmpty {
|
||||
if testSize <= buttonsAvailableSpace {
|
||||
if maxButtonWidth >= Button.Size.large.minimumWidth {
|
||||
//if there is enough room for all buttons
|
||||
if maxButtonWidth * buttonCount <= buttonsAvailableSpace {
|
||||
for attribute in buttonAttributes {
|
||||
attribute.frame.size.width = buttonCalculatedPercentage.isZero ? min(attribute.frame.size.width, maxButtonWidth) : maxButtonWidth
|
||||
}
|
||||
} else {
|
||||
//if not enough room, give all buttons the same width
|
||||
for attribute in buttonAttributes {
|
||||
attribute.frame.size.width = buttonEqualSpacing
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user