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 {
open var image: UIImage? {
didSet {
setImage(image, for: .normal)
setImage(image, for: .selected)
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 {
open var title: String? {
didSet {
setTitle(title, for: .normal)
setTitle(title, for: .selected)
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 {
return
......@@ -129,6 +145,17 @@ open class Button: UIButton, Pulseable, PulseableLayer {
didSet {
setTitleColor(titleColor, for: .normal)
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 {
super.prepare()
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)
......@@ -508,18 +496,18 @@ extension TabBar {
fileprivate extension TabBar {
/// Updates the tabItems colors.
func updateTabItemColors() {
let normalColor = tabItemsColorForState[.normal]
let selectedColor = tabItemsColorForState[.selected]
let highlightedColor = tabItemsColorForState[.highlighted]
let normalColor = tabItemsColorForState[.normal]!
let selectedColor = tabItemsColorForState[.selected]!
let highlightedColor = tabItemsColorForState[.highlighted]!
for v in tabItems {
v.setTitleColor(normalColor, for: .normal)
v.setImage(v.image?.tint(with: normalColor), for: .normal)
v.setTitleColor(selectedColor, for: .selected)
v.setImage(v.image?.tint(with: selectedColor), for: .selected)
v.setTitleColor(highlightedColor, for: .highlighted)
v.tintColor = normalColor
v.setImage(v.image?.tint(with: highlightedColor), for: .highlighted)
}
selectedTabItem?.tintColor = selectedColor
}
/// 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