From f267b98438dbd5711e8d0124a3959f499476aea1 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 17 Oct 2019 11:57:30 -0400 Subject: [PATCH] constraints added. changes made. --- MVMCoreUI/Atoms/Views/Checkbox.swift | 35 ++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index c3879f96..a568622b 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -75,7 +75,7 @@ import MVMCore /// Color of the check mark. public var checkColor: UIColor = .black { didSet { - setshapeLayerStrokeColor(checkColor) + setShapeLayerStrokeColor(checkColor) } } @@ -115,6 +115,21 @@ import MVMCore } } + //-------------------------------------------------- + // MARK: - Constraints + //-------------------------------------------------- + + private var heightConstraint: NSLayoutConstraint? + private var widthConstraint: NSLayoutConstraint? + + /// Updates the height and width anchors of the Checkbox with the assigned value. + public var heigthWidthConstant: Int = Checkbox.defaultHeightWidth { + didSet { + heightConstraint?.constant = heigthWidthConstant + widthConstraint?.constant = heigthWidthConstant + } + } + //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- @@ -170,9 +185,15 @@ import MVMCore open func setupView() { + guard constraints.isEmpty else { return } + isUserInteractionEnabled = true translatesAutoresizingMaskIntoConstraints = false backgroundColor = .clear + + widthConstraint = widthAnchor.constraint(equalToConstant: Checkbox.defaultHeightWidth) + heightConstraint = heightAnchor.constraint(equalToConstant: Checkbox.defaultHeightWidth) + heightWidthIsActive(true) } //-------------------------------------------------- @@ -301,16 +322,16 @@ import MVMCore layer.borderColor = borderColor.cgColor backgroundColor = isSelected ? checkedBackgroundColor : unCheckedBackgroundColor alpha = 1.0 - setshapeLayerStrokeColor(checkColor) + setShapeLayerStrokeColor(checkColor) } else { layer.borderColor = UIColor.mfSilver().cgColor backgroundColor = .clear alpha = DisableOppacity - setshapeLayerStrokeColor(UIColor.mfSilver()) + setShapeLayerStrokeColor(UIColor.mfSilver()) } } - private func setshapeLayerStrokeColor(_ color: UIColor) { + private func setShapeLayerStrokeColor(_ color: UIColor) { if let shapeLayer = shapeLayer { CATransaction.withDisabledAnimations { @@ -319,6 +340,12 @@ import MVMCore } } + public func heightWidthIsActive(_ isActive: Bool) { + + heightConstraint?.isActive = isActive + widthConstraint?.isActive = isActive + } + //-------------------------------------------------- // MARK: - UITouch //--------------------------------------------------