Commit 9b69558f by Daniel Dahan

Added image states for TabItems used in TabBar and

parent 6cb79199
## 2.15.0
* [issue-1057](https://github.com/CosmicMind/Material/issues/1057): Added image states for TabItems used in TabBar and TabsController
## 2.14.0
* [issue-995](https://github.com/CosmicMind/Material/issues/995): Updated iOS 11 layout margins for NavigationBar.
......
Pod::Spec.new do |s|
s.name = 'Material'
s.version = '2.14.0'
s.version = '2.15.0'
s.swift_version = '4.0'
s.license = 'BSD-3-Clause'
s.summary = 'A UI/UX framework for creating beautiful applications.'
s.homepage = 'http://cosmicmind.com'
......
......@@ -267,7 +267,7 @@
96BCB7971CB40DC500C806FE /* NavigationDrawerController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationDrawerController.swift; sourceTree = "<group>"; };
96BCB7981CB40DC500C806FE /* Bar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Bar.swift; sourceTree = "<group>"; };
96BCB7991CB40DC500C806FE /* TransitionController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransitionController.swift; sourceTree = "<group>"; };
96BCB79A1CB40DC500C806FE /* TabBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = TabBar.swift; sourceTree = "<group>"; tabWidth = 4; };
96BCB79A1CB40DC500C806FE /* TabBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = TabBar.swift; sourceTree = "<group>"; tabWidth = 2; };
96BCB79C1CB40DC500C806FE /* TextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextField.swift; sourceTree = "<group>"; };
96BCB79D1CB40DC500C806FE /* TextStorage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextStorage.swift; sourceTree = "<group>"; };
96BCB79E1CB40DC500C806FE /* TextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextView.swift; sourceTree = "<group>"; };
......@@ -852,7 +852,7 @@
attributes = {
LastSwiftMigration = 0710;
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0900;
LastUpgradeCheck = 0930;
ORGANIZATIONNAME = "CosmicMind, Inc.";
TargetAttributes = {
963832351B88DFD80015F710 = {
......@@ -1024,12 +1024,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
......@@ -1085,12 +1087,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
......
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0920"
LastUpgradeVersion = "0930"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
......@@ -26,7 +26,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
......@@ -56,7 +55,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
......
Subproject commit 654928d706213db2cd9f71281361960177ad0c1d
Subproject commit b3595d023fdd3b64dede8c30bcaa08ee366cf249
......@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.13.7</string>
<string>2.15.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
......
......@@ -31,9 +31,103 @@
import UIKit
open class TabItem: FlatButton {
/// A dictionary of TabItemStates to UIColors for states.
fileprivate var colorForState = [TabItemState: UIColor]()
/// A dictionary of TabItemStates to UIImages for states.
fileprivate var imageForState = [TabItemState: UIImage]()
/// Sets the normal and highlighted image for the button.
open override var image: UIImage? {
didSet {
setTabItemImage(image, for: .normal)
setTabItemImage(image, for: .selected)
setTabItemImage(image, for: .highlighted)
super.image = image
}
}
open override func prepare() {
super.prepare()
pulseAnimation = .none
prepareImages()
prepareColors()
updateColors()
}
}
fileprivate extension TabItem {
/// Prepares the tabsItems images.
func prepareImages() {
imageForState[.normal] = image
imageForState[.selected] = image
imageForState[.highlighted] = image
}
/// Prepares the tabsItems colors.
func prepareColors() {
colorForState[.normal] = Color.grey.base
colorForState[.selected] = Color.blue.base
colorForState[.highlighted] = Color.blue.base
}
}
fileprivate extension TabItem {
/// Updates the tabItems colors.
func updateColors() {
let normalColor = colorForState[.normal]!
let selectedColor = colorForState[.selected]!
let highlightedColor = colorForState[.highlighted]!
setTitleColor(normalColor, for: .normal)
setImage(imageForState[.normal]?.tint(with: normalColor), for: .normal)
setTitleColor(selectedColor, for: .selected)
setImage(imageForState[.selected]?.tint(with: selectedColor), for: .selected)
setTitleColor(highlightedColor, for: .highlighted)
setImage(imageForState[.highlighted]?.tint(with: highlightedColor), for: .highlighted)
}
}
extension TabItem {
/**
Retrieves the tabItem color for a given state.
- Parameter for state: A TabItemState.
- Returns: A UIColor.
*/
open func getTabItemColor(for state: TabItemState) -> UIColor {
return colorForState[state]!
}
/**
Sets the color for the tabItem given a TabItemState.
- Parameter _ color: A UIColor.
- Parameter for state: A TabItemState.
*/
open func setTabItemColor(_ color: UIColor, for state: TabItemState) {
colorForState[state] = color
updateColors()
}
/**
Retrieves the tabItem image for a given state.
- Parameter for state: A TabItemState.
- Returns: An optional UIImage.
*/
open func getTabItemImage(for state: TabItemState) -> UIImage? {
return imageForState[state]
}
/**
Sets the image for the tabItem given a TabItemState.
- Parameter _ image: An optional UIImage.
- Parameter for state: A TabItemState.
*/
open func setTabItemImage(_ image: UIImage?, for state: TabItemState) {
imageForState[state] = image
updateColors()
}
}
......@@ -106,6 +200,9 @@ public enum TabBarStyle: Int {
}
open class TabBar: Bar {
/// A dictionary of TabItemLineStates to UIColors for the line.
fileprivate var lineColorForState = [TabItemLineState: UIColor]()
/// Only for inital load to get the line animation correct.
fileprivate var shouldNotAnimateLineView = false
......@@ -126,12 +223,6 @@ open class TabBar: Bar {
return w
}
/// A dictionary of TabItemStates to UIColors for tabItems.
fileprivate var tabItemsColorForState = [TabItemState: UIColor]()
/// A dictionary of TabItemLineStates to UIColors for the line.
fileprivate var lineColorForState = [TabItemLineState: UIColor]()
/// An enum that determines the tab bar style.
open var tabBarStyle = TabBarStyle.auto {
didSet {
......@@ -276,10 +367,8 @@ open class TabBar: Bar {
prepareScrollView()
prepareDivider()
prepareLine()
prepareTabItemsColor()
prepareLineColor()
updateTabItemColors()
updateLineColors()
}
}
......@@ -312,13 +401,6 @@ fileprivate extension TabBar {
selectedTabItem = tabItems.first
}
/// Prepares the tabsItems colors.
func prepareTabItemsColor() {
tabItemsColorForState[.normal] = Color.grey.base
tabItemsColorForState[.selected] = Color.blue.base
tabItemsColorForState[.highlighted] = Color.blue.base
}
/// Prepares the line colors.
func prepareLineColor() {
lineColorForState[.selected] = Color.blue.base
......@@ -405,6 +487,47 @@ fileprivate extension TabBar {
}
}
extension TabBar {
/**
Retrieves the tabItem color for a given state.
- Parameter for state: A TabItemState.
- Returns: A optional UIColor.
*/
open func getTabItemColor(for state: TabItemState) -> UIColor? {
return tabItems.first?.getTabItemColor(for: state)
}
/**
Sets the color for the tabItem given a TabItemState.
- Parameter _ color: A UIColor.
- Parameter for state: A TabItemState.
*/
open func setTabItemsColor(_ color: UIColor, for state: TabItemState) {
for v in tabItems {
v.setTabItemColor(color, for: state)
}
}
/**
Retrieves the line color for a given state.
- Parameter for state: A TabItemLineState.
- Returns: A UIColor.
*/
open func getLineColor(for state: TabItemLineState) -> UIColor {
return lineColorForState[state]!
}
/**
Sets the color for the line given a TabItemLineState.
- Parameter _ color: A UIColor.
- Parameter for state: A TabItemLineState.
*/
open func setLineColor(_ color: UIColor, for state: TabItemLineState) {
lineColorForState[state] = color
updateLineColors()
}
}
fileprivate extension TabBar {
/**
Removes the tabItem animation handler.
......@@ -452,63 +575,7 @@ extension TabBar {
}
}
extension TabBar {
/**
Retrieves the tabItem color for a given state.
- Parameter for state: A TabItemState.
- Returns: A UIColor.
*/
open func getTabItemColor(for state: TabItemState) -> UIColor {
return tabItemsColorForState[state]!
}
/**
Sets the color for the tabItems given a TabItemState.
- Parameter _ color: A UIColor.
- Parameter for state: A TabItemState.
*/
open func setTabItemsColor(_ color: UIColor, for state: TabItemState) {
tabItemsColorForState[state] = color
updateTabItemColors()
}
/**
Retrieves the line color for a given state.
- Parameter for state: A TabItemLineState.
- Returns: A UIColor.
*/
open func getLineColor(for state: TabItemLineState) -> UIColor {
return lineColorForState[state]!
}
/**
Sets the color for the line given a TabItemLineState.
- Parameter _ color: A UIColor.
- Parameter for state: A TabItemLineState.
*/
open func setLineColor(_ color: UIColor, for state: TabItemLineState) {
lineColorForState[state] = color
updateLineColors()
}
}
fileprivate extension TabBar {
/// Updates the tabItems colors.
func updateTabItemColors() {
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.setImage(v.image?.tint(with: highlightedColor), for: .highlighted)
}
}
/// Updates the line colors.
func updateLineColors() {
line.backgroundColor = lineColorForState[.selected]
......
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