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