Switch molecule
This commit is contained in:
parent
aac9db9ca5
commit
ddd8eb9d45
@ -17,14 +17,14 @@ import UIKit
|
|||||||
var isRequired = false
|
var isRequired = false
|
||||||
var delegateObject: DelegateObject?
|
var delegateObject: DelegateObject?
|
||||||
|
|
||||||
@objc func switchChanged() {
|
@objc func switchChanged() {
|
||||||
let delegate = delegateObject as? MVMCoreUIDelegateObject
|
let delegate = delegateObject as? MVMCoreUIDelegateObject
|
||||||
if let delegate = delegate {
|
if let delegate = delegate {
|
||||||
let formValidator = delegate.formValidationProtocol?.formValidatorModel?()
|
let formValidator = delegate.formValidationProtocol?.formValidatorModel?()
|
||||||
formValidator?.enableByValidation()
|
formValidator?.enableByValidation()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func setupView() {
|
open override func setupView() {
|
||||||
super.setupView()
|
super.setupView()
|
||||||
mvmSwitch.addTarget(self, action: #selector(Switch.switchChanged), for: .valueChanged)
|
mvmSwitch.addTarget(self, action: #selector(Switch.switchChanged), for: .valueChanged)
|
||||||
@ -34,7 +34,7 @@ import UIKit
|
|||||||
// label.translatesAutoresizingMaskIntoConstraints = false
|
// label.translatesAutoresizingMaskIntoConstraints = false
|
||||||
mvmSwitch.translatesAutoresizingMaskIntoConstraints = false
|
mvmSwitch.translatesAutoresizingMaskIntoConstraints = false
|
||||||
mfTextButton.translatesAutoresizingMaskIntoConstraints = false;
|
mfTextButton.translatesAutoresizingMaskIntoConstraints = false;
|
||||||
setupConstraints(forView: self)
|
setupConstraints()
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func updateView(_ size: CGFloat) {
|
public override func updateView(_ size: CGFloat) {
|
||||||
@ -54,7 +54,7 @@ import UIKit
|
|||||||
if let dict = json?.optionalDictionaryForKey("textButton") {
|
if let dict = json?.optionalDictionaryForKey("textButton") {
|
||||||
mfTextButton.setWithJSON(dict, delegateObject: delegateObject, additionalData: additionalData)
|
mfTextButton.setWithJSON(dict, delegateObject: delegateObject, additionalData: additionalData)
|
||||||
}
|
}
|
||||||
if let delegateObject = delegateObject as? MVMCoreUIDelegateObject {
|
if let delegateObject = delegateObject as? MVMCoreUIDelegateObject {
|
||||||
FormValidator.setupValidation(molecule: self, delegate: delegateObject.formValidationProtocol)
|
FormValidator.setupValidation(molecule: self, delegate: delegateObject.formValidationProtocol)
|
||||||
}
|
}
|
||||||
if let onColorString = json?.optionalStringForKey("onTintColor") {
|
if let onColorString = json?.optionalStringForKey("onTintColor") {
|
||||||
@ -71,32 +71,27 @@ import UIKit
|
|||||||
}
|
}
|
||||||
// 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()
|
updateContraints()
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateContraints() {
|
func updateContraints() {
|
||||||
if let isEmptyText = label.text?.isEmpty,isEmptyText == false{
|
if let isEmptyText = label.text?.isEmpty,isEmptyText == false {
|
||||||
topConstraint_Switch?.priority = UILayoutPriority(rawValue:249)
|
topConstraint_Switch?.priority = UILayoutPriority(rawValue:249)
|
||||||
NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinCenterX: false, pinCenterY: true)
|
NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinCenterX: false, pinCenterY: true)
|
||||||
|
_ = NSLayoutConstraint(pinFirstView: mvmSwitch, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true)
|
||||||
}
|
}
|
||||||
layoutIfNeeded()
|
layoutIfNeeded()
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupConstraints(forView view: UIView) {
|
func setupConstraints() {
|
||||||
NSLayoutConstraint.constraintPinLeftSubview(label, leftConstant: 0)
|
NSLayoutConstraint.constraintPinLeftSubview(label, leftConstant: 0)
|
||||||
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)
|
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: .greaterThanOrEqual)
|
||||||
topConstraint_Switch = dict?[ConstraintTop] as? NSLayoutConstraint
|
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)
|
|
||||||
|
|
||||||
if label.text?.isEmpty ?? false == false {
|
|
||||||
_ = NSLayoutConstraint(pinFirstView: mvmSwitch, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func isValidField() -> Bool {
|
public func isValidField() -> Bool {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user