Switch molecule
This commit is contained in:
parent
85e9c56dcf
commit
281a10f7e1
@ -10,9 +10,11 @@ import UIKit
|
|||||||
|
|
||||||
@objcMembers public class Switch: ViewConstrainingView, FormValidationProtocol{
|
@objcMembers public class Switch: ViewConstrainingView, FormValidationProtocol{
|
||||||
public var mvmSwitch = MVMCoreUISwitch()
|
public var mvmSwitch = MVMCoreUISwitch()
|
||||||
var label = Label()
|
public var label = Label()
|
||||||
var mfTextButton = MFTextButton()
|
public var mfTextButton = MFTextButton()
|
||||||
var isRequired: Bool! = false
|
var topConstraint_Switch: NSLayoutConstraint?
|
||||||
|
var bottomConstraint_textBtn: NSLayoutConstraint?
|
||||||
|
var isRequired = false
|
||||||
var delegateObject: DelegateObject?
|
var delegateObject: DelegateObject?
|
||||||
|
|
||||||
@objc func switchChanged() {
|
@objc func switchChanged() {
|
||||||
@ -44,7 +46,7 @@ import UIKit
|
|||||||
|
|
||||||
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) {
|
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||||
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
||||||
isRequired = json?[KeyRequired] as? Bool
|
isRequired = json?[KeyRequired] as? Bool ?? false
|
||||||
self.delegateObject = delegateObject
|
self.delegateObject = delegateObject
|
||||||
if let dict = json?.optionalDictionaryForKey("label") {
|
if let dict = json?.optionalDictionaryForKey("label") {
|
||||||
label.setWithJSON(dict, delegateObject: delegateObject, additionalData: additionalData)
|
label.setWithJSON(dict, delegateObject: delegateObject, additionalData: additionalData)
|
||||||
@ -67,19 +69,30 @@ import UIKit
|
|||||||
if let offKnobColorString = json?.optionalStringForKey("offKnobTintColor") {
|
if let offKnobColorString = json?.optionalStringForKey("offKnobTintColor") {
|
||||||
mvmSwitch.offKnobTintColor = .mfGet(forHex: offKnobColorString)
|
mvmSwitch.offKnobTintColor = .mfGet(forHex: offKnobColorString)
|
||||||
}
|
}
|
||||||
// mvmSwitch.isOn = json?.optionalBoolForKey("state") ?? false
|
// mvmSwitch.isOn = json?.optionalBoolForKey("state") ?? false
|
||||||
mvmSwitch.setState(json?.optionalBoolForKey("state") ?? false, animated: true)
|
mvmSwitch.setState(json?.optionalBoolForKey("state") ?? false, animated: true)
|
||||||
|
//updateContraints()
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateContraints() {
|
||||||
|
if let isEmptyText = label.text?.isEmpty,isEmptyText == false{
|
||||||
|
topConstraint_Switch?.priority = UILayoutPriority(rawValue:249)
|
||||||
|
NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinCenterX: false, pinCenterY: true)
|
||||||
|
}
|
||||||
|
layoutIfNeeded()
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupConstraints(forView view: UIView) {
|
func setupConstraints(forView view: UIView) {
|
||||||
NSLayoutConstraint.constraintPinLeftSubview(label, leftConstant: 0)
|
NSLayoutConstraint.constraintPinLeftSubview(label, leftConstant: 0)
|
||||||
NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinTop: true, topConstant: 0, topRelation: .equal, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: true, rightConstant: 0, rightRelation: .equal)
|
let dict = NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinTop: true, topConstant: 0, topRelation: .greaterThanOrEqual, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: true, rightConstant: 0, rightRelation: .equal)
|
||||||
|
topConstraint_Switch = dict?[ConstraintTop] as? NSLayoutConstraint
|
||||||
NSLayoutConstraint.constraintPinTopSubview(label, topConstant: 0)
|
NSLayoutConstraint.constraintPinTopSubview(label, topConstant: 0)
|
||||||
_ = NSLayoutConstraint(pinFirstView: label, toSecondView: mvmSwitch, withConstant: PaddingOne, directionVertical: false)
|
_ = NSLayoutConstraint(pinFirstView: label, toSecondView: mvmSwitch, withConstant: PaddingOne, directionVertical: false)
|
||||||
_ = NSLayoutConstraint(pinFirstView: label, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true)
|
_ = NSLayoutConstraint(pinFirstView: label, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true)
|
||||||
NSLayoutConstraint.constraintPinLeftSubview(mfTextButton, leftConstant: 0)
|
NSLayoutConstraint.constraintPinLeftSubview(mfTextButton, leftConstant: 0)
|
||||||
NSLayoutConstraint.constraintPinBottomSubview(mfTextButton, bottomConstant: 0)
|
NSLayoutConstraint.constraintPinBottomSubview(mfTextButton, bottomConstant: 0)
|
||||||
NSLayoutConstraint.constraintPinRightSubview(mfTextButton, rightConstant: 0)
|
// NSLayoutConstraint.constraintPinRightSubview(mfTextButton, rightConstant: 0)
|
||||||
|
|
||||||
if label.text?.isEmpty ?? false == false {
|
if label.text?.isEmpty ?? false == false {
|
||||||
_ = NSLayoutConstraint(pinFirstView: mvmSwitch, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true)
|
_ = NSLayoutConstraint(pinFirstView: mvmSwitch, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true)
|
||||||
}
|
}
|
||||||
@ -108,3 +121,4 @@ import UIKit
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user