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