constraints added. changes made.

This commit is contained in:
Kevin G Christiano 2019-10-17 11:57:30 -04:00
parent 5ef9754e2c
commit f267b98438

View File

@ -75,7 +75,7 @@ import MVMCore
/// Color of the check mark. /// Color of the check mark.
public var checkColor: UIColor = .black { public var checkColor: UIColor = .black {
didSet { 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 // MARK: - Initializers
//-------------------------------------------------- //--------------------------------------------------
@ -170,9 +185,15 @@ import MVMCore
open func setupView() { open func setupView() {
guard constraints.isEmpty else { return }
isUserInteractionEnabled = true isUserInteractionEnabled = true
translatesAutoresizingMaskIntoConstraints = false translatesAutoresizingMaskIntoConstraints = false
backgroundColor = .clear 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 layer.borderColor = borderColor.cgColor
backgroundColor = isSelected ? checkedBackgroundColor : unCheckedBackgroundColor backgroundColor = isSelected ? checkedBackgroundColor : unCheckedBackgroundColor
alpha = 1.0 alpha = 1.0
setshapeLayerStrokeColor(checkColor) setShapeLayerStrokeColor(checkColor)
} else { } else {
layer.borderColor = UIColor.mfSilver().cgColor layer.borderColor = UIColor.mfSilver().cgColor
backgroundColor = .clear backgroundColor = .clear
alpha = DisableOppacity alpha = DisableOppacity
setshapeLayerStrokeColor(UIColor.mfSilver()) setShapeLayerStrokeColor(UIColor.mfSilver())
} }
} }
private func setshapeLayerStrokeColor(_ color: UIColor) { private func setShapeLayerStrokeColor(_ color: UIColor) {
if let shapeLayer = shapeLayer { if let shapeLayer = shapeLayer {
CATransaction.withDisabledAnimations { CATransaction.withDisabledAnimations {
@ -319,6 +340,12 @@ import MVMCore
} }
} }
public func heightWidthIsActive(_ isActive: Bool) {
heightConstraint?.isActive = isActive
widthConstraint?.isActive = isActive
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - UITouch // MARK: - UITouch
//-------------------------------------------------- //--------------------------------------------------