removed unneded optional wrapper
This commit is contained in:
parent
9c59ff13ab
commit
be29a5dfbc
@ -25,13 +25,13 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
/// Holds the on and off colors for the container.
|
/// Holds the on and off colors for the container.
|
||||||
public var containerTintColor: (on: UIColor, off: UIColor)? = (on: .mvmGreen, off: .mvmBlack)
|
public var containerTintColor: (on: UIColor, off: UIColor) = (on: .mvmGreen, off: .mvmBlack)
|
||||||
|
|
||||||
/// Holds the on and off colors for the knob.
|
/// Holds the on and off colors for the knob.
|
||||||
public var knobTintColor: (on: UIColor, off: UIColor)? = (on: .mvmWhite, off: .mvmWhite)
|
public var knobTintColor: (on: UIColor, off: UIColor) = (on: .mvmWhite, off: .mvmWhite)
|
||||||
|
|
||||||
/// Holds the on and off colors for the disabled state..
|
/// Holds the on and off colors for the disabled state..
|
||||||
public var disabledTintColor: (container: UIColor, knob: UIColor)? = (container: .mvmCoolGray3, knob: .mvmWhite)
|
public var disabledTintColor: (container: UIColor, knob: UIColor) = (container: .mvmCoolGray3, knob: .mvmWhite)
|
||||||
|
|
||||||
/// Set this flag to false if you do not want to animate state changes.
|
/// Set this flag to false if you do not want to animate state changes.
|
||||||
public var isAnimated = true
|
public var isAnimated = true
|
||||||
@ -62,8 +62,8 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
|||||||
didSet {
|
didSet {
|
||||||
isUserInteractionEnabled = isEnabled
|
isUserInteractionEnabled = isEnabled
|
||||||
changeStateNoAnimation(isEnabled ? isOn : false)
|
changeStateNoAnimation(isEnabled ? isOn : false)
|
||||||
backgroundColor = isEnabled ? (isOn ? containerTintColor?.on : containerTintColor?.off) : disabledTintColor?.container
|
backgroundColor = isEnabled ? (isOn ? containerTintColor.on : containerTintColor.off) : disabledTintColor.container
|
||||||
knobView.backgroundColor = isEnabled ? (isOn ? knobTintColor?.on : knobTintColor?.off) : disabledTintColor?.knob
|
knobView.backgroundColor = isEnabled ? (isOn ? knobTintColor.on : knobTintColor.off) : disabledTintColor.knob
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,12 +80,12 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
|||||||
if isAnimated {
|
if isAnimated {
|
||||||
UIView.animate(withDuration: 0.2, delay: 0.0, options: .curveEaseIn, animations: {
|
UIView.animate(withDuration: 0.2, delay: 0.0, options: .curveEaseIn, animations: {
|
||||||
if self.isOn {
|
if self.isOn {
|
||||||
self.knobView.backgroundColor = self.knobTintColor?.on
|
self.knobView.backgroundColor = self.knobTintColor.on
|
||||||
self.backgroundColor = self.containerTintColor?.on
|
self.backgroundColor = self.containerTintColor.on
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
self.knobView.backgroundColor = self.knobTintColor?.off
|
self.knobView.backgroundColor = self.knobTintColor.off
|
||||||
self.backgroundColor = self.containerTintColor?.off
|
self.backgroundColor = self.containerTintColor.off
|
||||||
}
|
}
|
||||||
}, completion: nil)
|
}, completion: nil)
|
||||||
|
|
||||||
@ -96,8 +96,8 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
|||||||
}, completion: nil)
|
}, completion: nil)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
backgroundColor = isOn ? containerTintColor?.on : containerTintColor?.off
|
backgroundColor = isOn ? containerTintColor.on : containerTintColor.off
|
||||||
knobView.backgroundColor = isOn ? knobTintColor?.on : knobTintColor?.off
|
knobView.backgroundColor = isOn ? knobTintColor.on : knobTintColor.off
|
||||||
self.constrainKnob()
|
self.constrainKnob()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,7 +206,7 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
|||||||
widthConstraint?.isActive = true
|
widthConstraint?.isActive = true
|
||||||
|
|
||||||
layer.cornerRadius = Self.containerSize.height / 2.0
|
layer.cornerRadius = Self.containerSize.height / 2.0
|
||||||
backgroundColor = containerTintColor?.off
|
backgroundColor = containerTintColor.off
|
||||||
|
|
||||||
addSubview(knobView)
|
addSubview(knobView)
|
||||||
|
|
||||||
@ -226,8 +226,8 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
|||||||
public override func reset() {
|
public override func reset() {
|
||||||
super.reset()
|
super.reset()
|
||||||
|
|
||||||
backgroundColor = containerTintColor?.off
|
backgroundColor = containerTintColor.off
|
||||||
knobView.backgroundColor = knobTintColor?.off
|
knobView.backgroundColor = knobTintColor.off
|
||||||
isAnimated = true
|
isAnimated = true
|
||||||
isOn = false
|
isOn = false
|
||||||
constrainKnob()
|
constrainKnob()
|
||||||
@ -348,10 +348,10 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
|||||||
|
|
||||||
FormValidator.setupValidation(for: model, delegate: delegateObject?.formHolderDelegate)
|
FormValidator.setupValidation(for: model, delegate: delegateObject?.formHolderDelegate)
|
||||||
|
|
||||||
containerTintColor?.on = model.onTintColor.uiColor
|
containerTintColor.on = model.onTintColor.uiColor
|
||||||
containerTintColor?.off = model.offTintColor.uiColor
|
containerTintColor.off = model.offTintColor.uiColor
|
||||||
knobTintColor?.on = model.onKnobTintColor.uiColor
|
knobTintColor.on = model.onKnobTintColor.uiColor
|
||||||
knobTintColor?.off = model.offKnobTintColor.uiColor
|
knobTintColor.off = model.offKnobTintColor.uiColor
|
||||||
changeStateNoAnimation(model.state)
|
changeStateNoAnimation(model.state)
|
||||||
isAnimated = model.animated
|
isAnimated = model.animated
|
||||||
isEnabled = model.enabled
|
isEnabled = model.enabled
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user