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