refactored textWidth into a enum
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
27af806281
commit
2956dc294e
@ -130,37 +130,33 @@ open class Tilelet: TileContainer {
|
||||
$0.name = .rightArrow
|
||||
}
|
||||
|
||||
private var _textWidth: CGFloat?
|
||||
open var textWidth: CGFloat? {
|
||||
public enum TextWidth {
|
||||
case value(CGFloat)
|
||||
case percentage(CGFloat)
|
||||
}
|
||||
|
||||
private var _textWidth: TextWidth?
|
||||
|
||||
/// If provided, width of Button components will be rendered based on this value. If omitted, default button widths are rendered.
|
||||
open var textWidth: TextWidth? {
|
||||
get { _textWidth }
|
||||
set {
|
||||
if let newValue, newValue > 44.0 {
|
||||
_textWidth = newValue
|
||||
if _textPercentage != nil {
|
||||
_textPercentage = nil
|
||||
if let newValue {
|
||||
switch newValue {
|
||||
case .percentage(let percentage):
|
||||
if percentage >= 10 && percentage <= 100.0 {
|
||||
_textWidth = newValue
|
||||
}
|
||||
case .value(let value):
|
||||
if value > 44.0 {
|
||||
_textWidth = newValue
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_textWidth = nil
|
||||
}
|
||||
setNeedsUpdate()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private var _textPercentage: CGFloat?
|
||||
open var textPercentage: CGFloat? {
|
||||
get { _textPercentage }
|
||||
set {
|
||||
if let newValue, newValue >= 5 && newValue <= 100.0 {
|
||||
_textPercentage = newValue
|
||||
if textWidth != nil {
|
||||
_textWidth = nil
|
||||
}
|
||||
} else {
|
||||
_textPercentage = nil
|
||||
}
|
||||
setNeedsUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
open var textPostion: TextPosition = .top { didSet { setNeedsUpdate() }}
|
||||
@ -319,22 +315,20 @@ open class Tilelet: TileContainer {
|
||||
titleLockupTrailingConstraint?.isActive = true
|
||||
|
||||
titleLockupWidthConstraint?.isActive = false
|
||||
titleLockupWidthConstraint = titleLockup.widthAnchor.constraint(equalToConstant: textWidth)
|
||||
titleLockupWidthConstraint?.isActive = true
|
||||
|
||||
} else if let textPercentage {
|
||||
titleLockupTrailingConstraint?.isActive = false
|
||||
titleLockupTrailingConstraint = titleLockup.trailingAnchor.constraint(lessThanOrEqualTo: titleLockupContainerView.trailingAnchor)
|
||||
titleLockupTrailingConstraint?.isActive = true
|
||||
|
||||
titleLockupWidthConstraint?.isActive = false
|
||||
titleLockupWidthConstraint = NSLayoutConstraint(item: titleLockup,
|
||||
attribute: .width,
|
||||
relatedBy: .equal,
|
||||
toItem: containerView,
|
||||
attribute: .width,
|
||||
multiplier: textPercentage / 100,
|
||||
constant: 0.0)
|
||||
switch textWidth {
|
||||
case .value(let value):
|
||||
titleLockupWidthConstraint = titleLockup.widthAnchor.constraint(equalToConstant: value)
|
||||
case .percentage(let percentage):
|
||||
titleLockupWidthConstraint = NSLayoutConstraint(item: titleLockup,
|
||||
attribute: .width,
|
||||
relatedBy: .equal,
|
||||
toItem: containerView,
|
||||
attribute: .width,
|
||||
multiplier: percentage / 100,
|
||||
constant: 0.0)
|
||||
}
|
||||
|
||||
titleLockupWidthConstraint?.isActive = true
|
||||
|
||||
} else {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user