Commit 81909af0 by Orkhan Alikhanov

Added button on and off image support for switch

parent e56de5fd
...@@ -112,6 +112,22 @@ open class Switch: UIControl, Themeable { ...@@ -112,6 +112,22 @@ open class Switch: UIControl, Themeable {
} }
} }
/// Button on image.
@IBInspectable
open var buttonOnImage: UIImage? {
didSet {
styleForState(state: switchState)
}
}
/// Button off image.
@IBInspectable
open var buttonOffImage: UIImage? {
didSet {
styleForState(state: switchState)
}
}
/// Track on color. /// Track on color.
@IBInspectable @IBInspectable
open var trackOnColor = Color.clear { open var trackOnColor = Color.clear {
...@@ -160,6 +176,23 @@ open class Switch: UIControl, Themeable { ...@@ -160,6 +176,23 @@ open class Switch: UIControl, Themeable {
} }
} }
/// Button on disabled image.
@IBInspectable
open var buttonOnDisabledImage: UIImage? {
didSet {
styleForState(state: switchState)
}
}
/// Button off disabled image.
@IBInspectable
open var buttonOffDisabledImage: UIImage? {
didSet {
styleForState(state: switchState)
}
}
/// Track view reference. /// Track view reference.
open fileprivate(set) var track: UIView { open fileprivate(set) var track: UIView {
didSet { didSet {
...@@ -416,9 +449,11 @@ fileprivate extension Switch { ...@@ -416,9 +449,11 @@ fileprivate extension Switch {
if .on == state { if .on == state {
button.backgroundColor = buttonOnColor button.backgroundColor = buttonOnColor
track.backgroundColor = trackOnColor track.backgroundColor = trackOnColor
button.image = buttonOnImage
} else { } else {
button.backgroundColor = buttonOffColor button.backgroundColor = buttonOffColor
track.backgroundColor = trackOffColor track.backgroundColor = trackOffColor
button.image = buttonOffImage
} }
} }
...@@ -430,9 +465,11 @@ fileprivate extension Switch { ...@@ -430,9 +465,11 @@ fileprivate extension Switch {
if .on == state { if .on == state {
button.backgroundColor = buttonOnDisabledColor button.backgroundColor = buttonOnDisabledColor
track.backgroundColor = trackOnDisabledColor track.backgroundColor = trackOnDisabledColor
button.image = buttonOnDisabledImage
} else { } else {
button.backgroundColor = buttonOffDisabledColor button.backgroundColor = buttonOffDisabledColor
track.backgroundColor = trackOffDisabledColor track.backgroundColor = trackOffDisabledColor
button.image = buttonOffDisabledImage
} }
} }
......
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