setting button style and constraints.
This commit is contained in:
parent
5f6e987da8
commit
2a1db08ab7
@ -34,8 +34,13 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
|
|||||||
// MARK: - Constraints
|
// MARK: - Constraints
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
public var widthConstraint: NSLayoutConstraint?
|
public var widthConstraint: NSLayoutConstraint {
|
||||||
public var minimumWidthConstraint: NSLayoutConstraint?
|
return widthAnchor.constraint(equalToConstant: 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
public var minimumWidthConstraint: NSLayoutConstraint {
|
||||||
|
return widthAnchor.constraint(greaterThanOrEqualToConstant: buttonSize.minimumWidth())
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initializers
|
// MARK: - Initializers
|
||||||
@ -78,12 +83,14 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
|
|||||||
public func stylePrimary() {
|
public func stylePrimary() {
|
||||||
|
|
||||||
buttonModel?.setPrimaryFacade()
|
buttonModel?.setPrimaryFacade()
|
||||||
|
style()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The secondary styling for a button. Should be used for secondary buttons
|
/// The secondary styling for a button. Should be used for secondary buttons
|
||||||
public func styleSecondary() {
|
public func styleSecondary() {
|
||||||
|
|
||||||
buttonModel?.setSecondaryFacade()
|
buttonModel?.setSecondaryFacade()
|
||||||
|
style()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Styles the button based on the model style
|
/// Styles the button based on the model style
|
||||||
@ -199,12 +206,13 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
|
|||||||
layer.cornerRadius = getInnerPadding()
|
layer.cornerRadius = getInnerPadding()
|
||||||
contentEdgeInsets = getContentEdgeInsets()
|
contentEdgeInsets = getContentEdgeInsets()
|
||||||
|
|
||||||
if let contraint = buttonModel?.width, (widthConstraint == nil || widthConstraint?.constant != contraint) {
|
if let contraint = buttonModel?.width, widthConstraint.constant != contraint {
|
||||||
widthConstraint = widthAnchor.constraint(equalToConstant: contraint)
|
widthConstraint.constant = contraint
|
||||||
widthConstraint?.isActive = true
|
widthConstraint.isActive = true
|
||||||
} else if minimumWidthConstraint == nil {
|
minimumWidthConstraint.isActive = false
|
||||||
minimumWidthConstraint = widthAnchor.constraint(greaterThanOrEqualToConstant: buttonSize.minimumWidth())
|
} else if !minimumWidthConstraint.isActive {
|
||||||
minimumWidthConstraint?.isActive = true
|
minimumWidthConstraint.isActive = true
|
||||||
|
widthConstraint.isActive = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user