Commit aa4f01ee by Daniel Dahan

issue-260: fixed issue where MaterialSwitch color was not propagating until engaged

parent 83c4c4a6
......@@ -130,11 +130,11 @@ public class BottomNavigationController : UITabBarController, UITabBarController
/// Handles transitions when tabBarItems are pressed.
public func tabBarController(tabBarController: UITabBarController, animationControllerForTransitionFromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
let fromVC: UIViewController? = fromVC
let toVC: UIViewController? = toVC
if nil == fromVC || nil == toVC {
return nil
}
let fVC: UIViewController? = fromVC
let tVC: UIViewController? = toVC
if nil == fVC || nil == tVC {
return nil
}
return .Fade == transitionAnimation ? BottomNavigationFadeAnimatedTransitioning() : nil
}
......
......@@ -125,28 +125,60 @@ public class MaterialSwitch : UIControl {
}
/// Button on color.
@IBInspectable public var buttonOnColor: UIColor = MaterialColor.clear
@IBInspectable public var buttonOnColor: UIColor = MaterialColor.clear {
didSet {
styleForState(switchState)
}
}
/// Button off color.
@IBInspectable public var buttonOffColor: UIColor = MaterialColor.clear
@IBInspectable public var buttonOffColor: UIColor = MaterialColor.clear {
didSet {
styleForState(switchState)
}
}
/// Track on color.
@IBInspectable public var trackOnColor: UIColor = MaterialColor.clear
@IBInspectable public var trackOnColor: UIColor = MaterialColor.clear {
didSet {
styleForState(switchState)
}
}
/// Track off color.
@IBInspectable public var trackOffColor: UIColor = MaterialColor.clear
@IBInspectable public var trackOffColor: UIColor = MaterialColor.clear {
didSet {
styleForState(switchState)
}
}
/// Button on disabled color.
@IBInspectable public var buttonOnDisabledColor: UIColor = MaterialColor.clear
@IBInspectable public var buttonOnDisabledColor: UIColor = MaterialColor.clear {
didSet {
styleForState(switchState)
}
}
/// Track on disabled color.
@IBInspectable public var trackOnDisabledColor: UIColor = MaterialColor.clear
@IBInspectable public var trackOnDisabledColor: UIColor = MaterialColor.clear {
didSet {
styleForState(switchState)
}
}
/// Button off disabled color.
@IBInspectable public var buttonOffDisabledColor: UIColor = MaterialColor.clear
@IBInspectable public var buttonOffDisabledColor: UIColor = MaterialColor.clear {
didSet {
styleForState(switchState)
}
}
/// Track off disabled color.
@IBInspectable public var trackOffDisabledColor: UIColor = MaterialColor.clear
@IBInspectable public var trackOffDisabledColor: UIColor = MaterialColor.clear {
didSet {
styleForState(switchState)
}
}
/// Track view reference.
public private(set) var trackLayer: MaterialLayer {
......@@ -264,6 +296,24 @@ public class MaterialSwitch : UIControl {
}
/**
An initializer that initializes the object with a CGRect object.
If AutoLayout is used, it is better to initilize the instance
using the init(state:style:size:) initializer, or set the CGRect
to CGRectNull.
- Parameter frame: A CGRect instance.
*/
public override init(frame: CGRect) {
trackLayer = MaterialLayer()
button = FabButton()
super.init(frame: frame)
prepareTrack()
prepareButton()
prepareSwitchSize(.Default)
prepareSwitchStyle(.LightContent)
prepareSwitchState(.Off)
}
/**
An initializer that sets the state, style, and size of the MaterialSwitch instance.
- Parameter state: A MaterialSwitchState value.
- Parameter style: A MaterialSwitchStyle value.
......@@ -425,7 +475,7 @@ public class MaterialSwitch : UIControl {
*/
private func styleForState(state: MaterialSwitchState) {
if enabled {
updateColorForEnabledState(state)
updateColorForState(state)
} else {
updateColorForDisabledState(state)
}
......@@ -435,7 +485,7 @@ public class MaterialSwitch : UIControl {
Updates the coloring for the enabled state.
- Parameter state: MaterialSwitchState.
*/
private func updateColorForEnabledState(state: MaterialSwitchState) {
private func updateColorForState(state: MaterialSwitchState) {
if .On == state {
button.backgroundColor = buttonOnColor
trackLayer.backgroundColor = trackOnColor.CGColor
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment