Skip to content

Commit

Permalink
Merge pull request Ramotion#85 from lutc/master
Browse files Browse the repository at this point in the history
Added posibility to change background
  • Loading branch information
0ber committed Feb 26, 2016
2 parents bb80a6c + 87b1e4b commit 4cb5054
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions RAMAnimatedTabBarController/RAMAnimatedTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public class RAMAnimatedTabBarItem: UITabBarItem {

@IBInspectable public var textColor: UIColor = UIColor.blackColor()
@IBInspectable public var iconColor: UIColor = UIColor.clearColor() // if alpha color is 0 color ignoring

@IBInspectable var bgDefaultColor: UIColor = UIColor.grayColor()
@IBInspectable var bgSelectedColor: UIColor = UIColor.whiteColor()

public var badge: RAMBadge? // use badgeValue to show badge

public var iconView: (icon: UIImageView, textLabel: UILabel)?
Expand Down Expand Up @@ -179,6 +181,8 @@ public class RAMAnimatedTabBarController: UITabBarController {
textLabel.font = UIFont.systemFontOfSize(10)
textLabel.textAlignment = NSTextAlignment.Center
textLabel.translatesAutoresizingMaskIntoConstraints = false

container.backgroundColor = (items as [RAMAnimatedTabBarItem])[index].bgDefaultColor

container.addSubview(icon)
createConstraints(icon, container: container, size: itemImage.size, yOffset: -5)
Expand All @@ -191,6 +195,7 @@ public class RAMAnimatedTabBarController: UITabBarController {

if 0 == index { // selected first elemet
item.selectedState()
container.backgroundColor = (items as [RAMAnimatedTabBarItem])[index].bgSelectedColor
}

item.image = nil
Expand Down Expand Up @@ -319,13 +324,20 @@ public class RAMAnimatedTabBarController: UITabBarController {
where !shouldSelect {
return
}

if selectedIndex != currentIndex {
let animationItem : RAMAnimatedTabBarItem = items[currentIndex]
animationItem.playAnimation()

let deselectItem = items[selectedIndex]

let containerPrevious : UIView = deselectItem.iconView!.icon.superview!
containerPrevious.backgroundColor = items[currentIndex].bgDefaultColor

deselectItem.deselectAnimation()

let container : UIView = animationItem.iconView!.icon.superview!
container.backgroundColor = items[currentIndex].bgSelectedColor

selectedIndex = gestureView.tag
delegate?.tabBarController?(self, didSelectViewController: self)
Expand Down

0 comments on commit 4cb5054

Please sign in to comment.