Commit aa4f01ee by Daniel Dahan

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

parent 83c4c4a6
...@@ -130,9 +130,9 @@ public class BottomNavigationController : UITabBarController, UITabBarController ...@@ -130,9 +130,9 @@ public class BottomNavigationController : UITabBarController, UITabBarController
/// Handles transitions when tabBarItems are pressed. /// Handles transitions when tabBarItems are pressed.
public func tabBarController(tabBarController: UITabBarController, animationControllerForTransitionFromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { public func tabBarController(tabBarController: UITabBarController, animationControllerForTransitionFromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
let fromVC: UIViewController? = fromVC let fVC: UIViewController? = fromVC
let toVC: UIViewController? = toVC let tVC: UIViewController? = toVC
if nil == fromVC || nil == toVC { if nil == fVC || nil == tVC {
return nil return nil
} }
return .Fade == transitionAnimation ? BottomNavigationFadeAnimatedTransitioning() : nil return .Fade == transitionAnimation ? BottomNavigationFadeAnimatedTransitioning() : nil
......
...@@ -125,28 +125,60 @@ public class MaterialSwitch : UIControl { ...@@ -125,28 +125,60 @@ public class MaterialSwitch : UIControl {
} }
/// Button on color. /// Button on color.
@IBInspectable public var buttonOnColor: UIColor = MaterialColor.clear @IBInspectable public var buttonOnColor: UIColor = MaterialColor.clear {
didSet {
styleForState(switchState)
}
}
/// Button off color. /// Button off color.
@IBInspectable public var buttonOffColor: UIColor = MaterialColor.clear @IBInspectable public var buttonOffColor: UIColor = MaterialColor.clear {
didSet {
styleForState(switchState)
}
}
/// Track on color. /// Track on color.
@IBInspectable public var trackOnColor: UIColor = MaterialColor.clear @IBInspectable public var trackOnColor: UIColor = MaterialColor.clear {
didSet {
styleForState(switchState)
}
}
/// Track off color. /// Track off color.
@IBInspectable public var trackOffColor: UIColor = MaterialColor.clear @IBInspectable public var trackOffColor: UIColor = MaterialColor.clear {
didSet {
styleForState(switchState)
}
}
/// Button on disabled color. /// 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. /// 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. /// 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. /// Track off disabled color.
@IBInspectable public var trackOffDisabledColor: UIColor = MaterialColor.clear @IBInspectable public var trackOffDisabledColor: UIColor = MaterialColor.clear {
didSet {
styleForState(switchState)
}
}
/// Track view reference. /// Track view reference.
public private(set) var trackLayer: MaterialLayer { public private(set) var trackLayer: MaterialLayer {
...@@ -264,6 +296,24 @@ public class MaterialSwitch : UIControl { ...@@ -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. An initializer that sets the state, style, and size of the MaterialSwitch instance.
- Parameter state: A MaterialSwitchState value. - Parameter state: A MaterialSwitchState value.
- Parameter style: A MaterialSwitchStyle value. - Parameter style: A MaterialSwitchStyle value.
...@@ -425,7 +475,7 @@ public class MaterialSwitch : UIControl { ...@@ -425,7 +475,7 @@ public class MaterialSwitch : UIControl {
*/ */
private func styleForState(state: MaterialSwitchState) { private func styleForState(state: MaterialSwitchState) {
if enabled { if enabled {
updateColorForEnabledState(state) updateColorForState(state)
} else { } else {
updateColorForDisabledState(state) updateColorForDisabledState(state)
} }
...@@ -435,7 +485,7 @@ public class MaterialSwitch : UIControl { ...@@ -435,7 +485,7 @@ public class MaterialSwitch : UIControl {
Updates the coloring for the enabled state. Updates the coloring for the enabled state.
- Parameter state: MaterialSwitchState. - Parameter state: MaterialSwitchState.
*/ */
private func updateColorForEnabledState(state: MaterialSwitchState) { private func updateColorForState(state: MaterialSwitchState) {
if .On == state { if .On == state {
button.backgroundColor = buttonOnColor button.backgroundColor = buttonOnColor
trackLayer.backgroundColor = trackOnColor.CGColor 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