Checkbox in good place.
This commit is contained in:
parent
f5f994648a
commit
b032e40400
@ -17,13 +17,17 @@ import MVMCore
|
|||||||
public static let defaultHeightWidth: CGFloat = 18.0
|
public static let defaultHeightWidth: CGFloat = 18.0
|
||||||
|
|
||||||
/// The color of the background when checked.
|
/// The color of the background when checked.
|
||||||
public var checkedBackgroundColor: UIColor = .white
|
public var checkedBackgroundColor: UIColor?
|
||||||
|
|
||||||
/// The color of the background when unChecked.
|
/// The color of the background when unChecked. Will change of the view's background color.
|
||||||
public var unCheckedBackgroundColor: UIColor = .black
|
public var unCheckedBackgroundColor: UIColor = .white {
|
||||||
|
didSet (newColor) {
|
||||||
|
backgroundColor = newColor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// If true the border of this checkbox will be circular.
|
/// If true the border of this checkbox will be circular.
|
||||||
public var hasRoundCorners = false
|
public var hasRoundedCorners = false
|
||||||
|
|
||||||
// Action Block called when the switch is selected.
|
// Action Block called when the switch is selected.
|
||||||
public var actionBlock: ActionBlock?
|
public var actionBlock: ActionBlock?
|
||||||
@ -57,14 +61,20 @@ import MVMCore
|
|||||||
|
|
||||||
override open var isSelected: Bool {
|
override open var isSelected: Bool {
|
||||||
didSet {
|
didSet {
|
||||||
|
shapeLayer?.removeAllAnimations()
|
||||||
if isSelected {
|
if isSelected {
|
||||||
// layer.addSublayer(shapeLayer!)
|
if checkedBackgroundColor != nil {
|
||||||
// shapeLayer?.strokeEnd = 1
|
UIView.animate(withDuration: 0.2, delay: 0.1, options: .curveEaseOut, animations: {
|
||||||
shapeLayer?.removeAllAnimations()
|
self.backgroundColor = self.checkedBackgroundColor
|
||||||
|
})
|
||||||
|
}
|
||||||
shapeLayer?.add(checkedAnimation, forKey: "strokeEnd")
|
shapeLayer?.add(checkedAnimation, forKey: "strokeEnd")
|
||||||
} else {
|
} else {
|
||||||
// shapeLayer?.strokeEnd = 0
|
if checkedBackgroundColor != nil {
|
||||||
shapeLayer?.removeAllAnimations()
|
UIView.animate(withDuration: 0.2, delay: 0.1, options: .curveEaseOut, animations: {
|
||||||
|
self.backgroundColor = self.unCheckedBackgroundColor
|
||||||
|
})
|
||||||
|
}
|
||||||
shapeLayer?.add(uncheckedAnimation, forKey: "strokeEnd")
|
shapeLayer?.add(uncheckedAnimation, forKey: "strokeEnd")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,6 +128,11 @@ import MVMCore
|
|||||||
self.unCheckedBackgroundColor = unCheckedColor
|
self.unCheckedBackgroundColor = unCheckedColor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public convenience init(isCircular: Bool) {
|
||||||
|
self.init(frame: .zero)
|
||||||
|
hasRoundedCorners = isCircular
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Lifecycle
|
// MARK: - Lifecycle
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -125,13 +140,14 @@ import MVMCore
|
|||||||
override open func layoutSubviews() {
|
override open func layoutSubviews() {
|
||||||
super.layoutSubviews()
|
super.layoutSubviews()
|
||||||
drawCheck()
|
drawCheck()
|
||||||
|
layer.cornerRadius = hasRoundedCorners ? cornerRadiusValue : 0
|
||||||
|
backgroundColor = unCheckedBackgroundColor ?? .white
|
||||||
}
|
}
|
||||||
|
|
||||||
public func setupView() {
|
public func setupView() {
|
||||||
|
|
||||||
isUserInteractionEnabled = true
|
isUserInteractionEnabled = true
|
||||||
translatesAutoresizingMaskIntoConstraints = false
|
translatesAutoresizingMaskIntoConstraints = false
|
||||||
backgroundColor = .white
|
|
||||||
layer.borderWidth = 1
|
layer.borderWidth = 1
|
||||||
layer.borderColor = UIColor.black.cgColor
|
layer.borderColor = UIColor.black.cgColor
|
||||||
}
|
}
|
||||||
@ -145,7 +161,6 @@ import MVMCore
|
|||||||
|
|
||||||
isSelected.toggle()
|
isSelected.toggle()
|
||||||
actionBlock?()
|
actionBlock?()
|
||||||
drawCheck()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func sendActions(for controlEvents: UIControl.Event) {
|
open override func sendActions(for controlEvents: UIControl.Event) {
|
||||||
@ -153,7 +168,6 @@ import MVMCore
|
|||||||
|
|
||||||
isSelected.toggle()
|
isSelected.toggle()
|
||||||
actionBlock?()
|
actionBlock?()
|
||||||
drawCheck()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -181,6 +195,9 @@ import MVMCore
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
!!! -- DO NOT REMOVE -- !!!
|
||||||
|
(Unless Design changes the appearance of the checkmark).
|
||||||
|
|
||||||
// Offsets based on the 124x124 example checkmark
|
// Offsets based on the 124x124 example checkmark
|
||||||
let startXOffset: Float = 42.0 / 124.0 ~~ 0.33871
|
let startXOffset: Float = 42.0 / 124.0 ~~ 0.33871
|
||||||
let startYOffset: Float = 66.0 / 124.0 ~~ 0.53225
|
let startYOffset: Float = 66.0 / 124.0 ~~ 0.53225
|
||||||
@ -211,8 +228,8 @@ import MVMCore
|
|||||||
|
|
||||||
public func updateSelection(_ selected: Bool, animated: Bool) {
|
public func updateSelection(_ selected: Bool, animated: Bool) {
|
||||||
|
|
||||||
// shapeLayer?.removeFromSuperlayer()
|
// shapeLayer?.removeFromSuperlayer()
|
||||||
// shapeLayer = nil
|
// shapeLayer = nil
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
|
||||||
@ -268,19 +285,6 @@ import MVMCore
|
|||||||
return x < -faultTolerance || y < -faultTolerance || x > widthLimit || y > heightLimt
|
return x < -faultTolerance || y < -faultTolerance || x > widthLimit || y > heightLimt
|
||||||
}
|
}
|
||||||
|
|
||||||
// if checkbox.isSelected {
|
|
||||||
// UIView.animate(withDuration: 0.2, delay: 0.1, options: .curveEaseOut, animations: {
|
|
||||||
// self.checkbox.backgroundColor = self.checkedColor
|
|
||||||
// })
|
|
||||||
// checkbox.updateCheckSelected(true, animated: animated)
|
|
||||||
// } else {
|
|
||||||
// UIView.animate(withDuration: 0.2, delay: 0.1, options: .curveEaseOut, animations: {
|
|
||||||
// self.checkbox.backgroundColor = self.unCheckedColor
|
|
||||||
// })
|
|
||||||
//
|
|
||||||
// checkbox.updateCheckSelected(false, animated: animated)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if delegate && delegate.responds(to: #selector(formValidationProtocol)) && delegate.perform(#selector(formValidationProtocol)).responds(to: #selector(Unmanaged<AnyObject>.formValidatorModel)) {
|
// if delegate && delegate.responds(to: #selector(formValidationProtocol)) && delegate.perform(#selector(formValidationProtocol)).responds(to: #selector(Unmanaged<AnyObject>.formValidatorModel)) {
|
||||||
// let formValidator = delegate.perform(#selector(formValidationProtocol)).perform(#selector(Unmanaged<AnyObject>.formValidatorModel)) as? FormValidator
|
// let formValidator = delegate.perform(#selector(formValidationProtocol)).perform(#selector(Unmanaged<AnyObject>.formValidatorModel)) as? FormValidator
|
||||||
// formValidator?.enableByValidation()
|
// formValidator?.enableByValidation()
|
||||||
@ -313,7 +317,7 @@ import MVMCore
|
|||||||
[formValidator enableByValidation];
|
[formValidator enableByValidation];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Molecular
|
// MARK: - Molecular
|
||||||
@ -360,9 +364,13 @@ import MVMCore
|
|||||||
unCheckedBackgroundColor = UIColor.mfGet(forHex: unCheckedColorHex)
|
unCheckedBackgroundColor = UIColor.mfGet(forHex: unCheckedColorHex)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if let actionMap = dictionary.optionalDictionaryForKey("actionMap") {
|
if let isRound = dictionary["isRound"] as? Bool {
|
||||||
// actionBlock = { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) }
|
hasRoundedCorners = isRound
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
// if let actionMap = dictionary.optionalDictionaryForKey("actionMap") {
|
||||||
|
// actionBlock = { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -56,6 +56,7 @@
|
|||||||
layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: checkbox.bottomAnchor).isActive = true
|
layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: checkbox.bottomAnchor).isActive = true
|
||||||
checkbox.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor).isActive = true
|
checkbox.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor).isActive = true
|
||||||
checkbox.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
|
checkbox.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
|
||||||
|
checkbox.checkedBackgroundColor = .yellow
|
||||||
|
|
||||||
label.topAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.topAnchor).isActive = true
|
label.topAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.topAnchor).isActive = true
|
||||||
layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: label.bottomAnchor).isActive = true
|
layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: label.bottomAnchor).isActive = true
|
||||||
@ -98,11 +99,6 @@
|
|||||||
checkbox.unCheckedBackgroundColor = unCheckedColor
|
checkbox.unCheckedBackgroundColor = unCheckedColor
|
||||||
label.attributedText = attributedText
|
label.attributedText = attributedText
|
||||||
}
|
}
|
||||||
|
|
||||||
public convenience init(isRoundedCheckbox: Bool) {
|
|
||||||
self.init(frame: .zero)
|
|
||||||
checkbox.hasRoundCorners = isRoundedCheckbox
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Molecular
|
// MARK: - Molecular
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user