Commit a64fc985 by Daniel Dahan

samples issue-95: fixed TabBar image colors that were not correctly being set for a given state

parent 5434f208
...@@ -100,7 +100,15 @@ open class Button: UIButton, Pulseable, PulseableLayer { ...@@ -100,7 +100,15 @@ open class Button: UIButton, Pulseable, PulseableLayer {
open var image: UIImage? { open var image: UIImage? {
didSet { didSet {
setImage(image, for: .normal) setImage(image, for: .normal)
setImage(image, for: .selected)
setImage(image, for: .highlighted) setImage(image, for: .highlighted)
setImage(image, for: .disabled)
if #available(iOS 9, *) {
setImage(image, for: .application)
setImage(image, for: .focused)
setImage(image, for: .reserved)
}
} }
} }
...@@ -109,7 +117,15 @@ open class Button: UIButton, Pulseable, PulseableLayer { ...@@ -109,7 +117,15 @@ open class Button: UIButton, Pulseable, PulseableLayer {
open var title: String? { open var title: String? {
didSet { didSet {
setTitle(title, for: .normal) setTitle(title, for: .normal)
setTitle(title, for: .selected)
setTitle(title, for: .highlighted) setTitle(title, for: .highlighted)
setTitle(title, for: .disabled)
if #available(iOS 9, *) {
setTitle(title, for: .application)
setTitle(title, for: .focused)
setTitle(title, for: .reserved)
}
guard nil != title else { guard nil != title else {
return return
...@@ -129,6 +145,17 @@ open class Button: UIButton, Pulseable, PulseableLayer { ...@@ -129,6 +145,17 @@ open class Button: UIButton, Pulseable, PulseableLayer {
didSet { didSet {
setTitleColor(titleColor, for: .normal) setTitleColor(titleColor, for: .normal)
setTitleColor(titleColor, for: .highlighted) setTitleColor(titleColor, for: .highlighted)
setTitleColor(titleColor, for: .disabled)
if nil == selectedTitleColor {
setTitleColor(titleColor, for: .selected)
}
if #available(iOS 9, *) {
setTitleColor(titleColor, for: .application)
setTitleColor(titleColor, for: .focused)
setTitleColor(titleColor, for: .reserved)
}
} }
} }
......
...@@ -35,18 +35,6 @@ open class TabItem: FlatButton { ...@@ -35,18 +35,6 @@ open class TabItem: FlatButton {
super.prepare() super.prepare()
pulseAnimation = .none pulseAnimation = .none
} }
open override var isHighlighted: Bool {
didSet {
tintColor = titleColor(for: isHighlighted ? .highlighted : isSelected ? .selected : .normal)
}
}
open override var isSelected: Bool {
didSet {
tintColor = titleColor(for: isSelected ? .selected : .normal)
}
}
} }
@objc(TabItemState) @objc(TabItemState)
...@@ -508,18 +496,18 @@ extension TabBar { ...@@ -508,18 +496,18 @@ extension TabBar {
fileprivate extension TabBar { fileprivate extension TabBar {
/// Updates the tabItems colors. /// Updates the tabItems colors.
func updateTabItemColors() { func updateTabItemColors() {
let normalColor = tabItemsColorForState[.normal] let normalColor = tabItemsColorForState[.normal]!
let selectedColor = tabItemsColorForState[.selected] let selectedColor = tabItemsColorForState[.selected]!
let highlightedColor = tabItemsColorForState[.highlighted] let highlightedColor = tabItemsColorForState[.highlighted]!
for v in tabItems { for v in tabItems {
v.setTitleColor(normalColor, for: .normal) v.setTitleColor(normalColor, for: .normal)
v.setImage(v.image?.tint(with: normalColor), for: .normal)
v.setTitleColor(selectedColor, for: .selected) v.setTitleColor(selectedColor, for: .selected)
v.setImage(v.image?.tint(with: selectedColor), for: .selected)
v.setTitleColor(highlightedColor, for: .highlighted) v.setTitleColor(highlightedColor, for: .highlighted)
v.tintColor = normalColor v.setImage(v.image?.tint(with: highlightedColor), for: .highlighted)
} }
selectedTabItem?.tintColor = selectedColor
} }
/// Updates the line colors. /// Updates the line colors.
......
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