Skip to content

Commit

Permalink
added style settings for CBFlashyTabBarButton
Browse files Browse the repository at this point in the history
  • Loading branch information
askopin committed Jul 11, 2019
1 parent d4c66b2 commit 36e5c45
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CBTabBarController.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'CBTabBarController'
s.version = '0.9.4'
s.version = '0.9.5'
s.summary = 'One another nice animated tabbar'
s.homepage = 'https://github.com/Cuberto/cb-tabbar'
s.license = 'MIT'
Expand Down
6 changes: 3 additions & 3 deletions CBTabBarController/Classes/CBTabBarStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public struct CBTabMenu {
}

public enum CBTabBarStyle {
case flashy
case flashy(config: CBFlashyTabBarConfig?)
case fade
case gooey(menu: CBTabMenu)
}
Expand All @@ -65,8 +65,8 @@ internal extension CBTabBarStyle {
tabBar.buttonFactory = menuFactory
case .fade:
tabBar.buttonFactory = CBFadeTabButtonFactory()
case .flashy:
tabBar.buttonFactory = CBFlashyTabButtonFactory()
case let .flashy(config):
tabBar.buttonFactory = CBFlashyTabButtonFactory(config: config)
}
}
}
4 changes: 3 additions & 1 deletion CBTabBarController/Classes/Flashy/CBFlashyTabBarButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class CBFlashyTabBarButton: CBTabBarButton {

var selectAnimation: CBTabItemAnimation?
var deselectAnimation: CBTabItemAnimation?
var config: CBFlashyTabBarConfig?

private var _isSelected: Bool = false
override var isSelected: Bool {
get {
Expand Down Expand Up @@ -82,7 +84,7 @@ class CBFlashyTabBarButton: CBTabBarButton {

override var tintColor: UIColor! {
didSet {
tabImage.tintColor = tintColor.withAlphaComponent(0.4)
tabImage.tintColor = tintColor.withAlphaComponent(config?.deselectedOpacity ?? 0.4)
tabLabel.attributedText = (item as? CBExtendedTabItem)?.attributedTitle ?? attributedText(fortitle: item?.title)
dotView.backgroundColor = tintColor
badgeContainer.backgroundColor = item?.badgeColor ?? tintColor
Expand Down
17 changes: 16 additions & 1 deletion CBTabBarController/Classes/Flashy/CBFlashyTabButtonFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,28 @@

import UIKit

public struct CBFlashyTabBarConfig {
let deselectedOpacity: CGFloat

public init(deselectedOpacity: CGFloat) {
self.deselectedOpacity = max(0.0, min(1.0, deselectedOpacity))
}
}

class CBFlashyTabButtonFactory: CBTabButtonFactory {


let config: CBFlashyTabBarConfig?

init(config: CBFlashyTabBarConfig? = nil) {
self.config = config
}

private var animationSpeed: Double = 1.0

func buttons(forItems items: [UITabBarItem]) -> [CBTabBarButton] {
return items.map { item -> CBTabBarButton in
let button = CBFlashyTabBarButton(item: item)
button.config = config
button.selectAnimation = CBFlashyTabItemSelectAnimation(duration: 0.3 / animationSpeed)
button.deselectAnimation = CBFlashyTabItemDeselectAnimation(duration: 0.3 / animationSpeed)
return button
Expand Down
2 changes: 1 addition & 1 deletion CBTabBarController/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.9.3</string>
<string>0.9.5</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
</dict>
Expand Down
2 changes: 1 addition & 1 deletion Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ViewController: UIViewController {

@IBAction func btnFlashyPressed(_ sender: AnyObject) {
let tabBarController = createSampleTabController()
tabBarController.style = .flashy
tabBarController.style = .flashy(config: nil)
self.navigationController?.pushViewController(tabBarController, animated: true)
}

Expand Down

0 comments on commit 36e5c45

Please sign in to comment.