Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Cuberto/bubble-icon-tabbar
Browse files Browse the repository at this point in the history
  • Loading branch information
askopin committed Feb 20, 2019
2 parents d3c5e9d + 2dc6a13 commit fdd7229
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion BubbleTabBar.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = 'BubbleTabBar'
s.swift_version = '4.2'
s.version = '0.8.2'
s.version = '0.8.3'
s.summary = 'One another nice animated tabbar'
s.homepage = 'https://github.com/Cuberto/bubble-icon-tabbar'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
Expand Down
50 changes: 23 additions & 27 deletions BubbleTabBar/Classes/BubbleTabBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UIKit

open class BubbleTabBar: UITabBar {

private var buttons: [CBTabBarButton] = []
public var animationDuration: Double = 0.3

Expand All @@ -26,7 +26,7 @@ open class BubbleTabBar: UITabBar {
select(itemAt: index, animated: false)
}
}

open override var tintColor: UIColor! {
didSet {
buttons.forEach { button in
Expand All @@ -36,12 +36,12 @@ open class BubbleTabBar: UITabBar {
}
}
}

public override init(frame: CGRect) {
super.init(frame: frame)
configure()
}

public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
configure()
Expand Down Expand Up @@ -81,24 +81,24 @@ open class BubbleTabBar: UITabBar {
csContainerBottom.constant = -safeAreaInsets.bottom
} else { }
}

open override var items: [UITabBarItem]? {
didSet {
reloadViews()
}
}

open override func setItems(_ items: [UITabBarItem]?, animated: Bool) {
super.setItems(items, animated: animated)
reloadViews()
}

private var spacers: [UIView] = []
private var spaceLayoutGuides:[UILayoutGuide] = []

private func reloadViews() {
subviews.filter { String(describing: type(of: $0)) == "UITabBarButton" }.forEach { $0.removeFromSuperview() }
buttons.forEach { $0.removeFromSuperview()}
spacers.forEach { $0.removeFromSuperview()}
buttons.forEach { $0.removeFromSuperview() }
spaceLayoutGuides.forEach { self.container.removeLayoutGuide($0) }
buttons = items?.map { self.button(forItem: $0) } ?? []
buttons.forEach { (button) in
self.container.addSubview(button)
Expand All @@ -108,22 +108,18 @@ open class BubbleTabBar: UITabBar {
buttons.first?.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 10.0).isActive = true
buttons.last?.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -10.0).isActive = true
let viewCount = buttons.count - 1
spacers = []
spaceLayoutGuides = [];
for i in 0..<viewCount {
let spacer = UIView()
spacer.translatesAutoresizingMaskIntoConstraints = false
container.addSubview(spacer)
spacer.isHidden = true
spacer.topAnchor.constraint(equalTo: container.topAnchor).isActive = true
spacer.bottomAnchor.constraint(equalTo: container.bottomAnchor).isActive = true
let layoutGuide = UILayoutGuide()
container.addLayoutGuide(layoutGuide)
spaceLayoutGuides.append(layoutGuide)
let prevBtn = buttons[i]
let nextBtn = buttons[i + 1]
spacer.leadingAnchor.constraint(equalTo: prevBtn.trailingAnchor).isActive = true
spacer.trailingAnchor.constraint(equalTo: nextBtn.leadingAnchor).isActive = true
spacers.append(spacer)
layoutGuide.leadingAnchor.constraint(equalTo: prevBtn.trailingAnchor).isActive = true
layoutGuide.trailingAnchor.constraint(equalTo: nextBtn.leadingAnchor).isActive = true
}
for spacer in spacers[1...] {
spacer.widthAnchor.constraint(equalTo: spacers[0].widthAnchor, multiplier: 1.0).isActive = true
for layoutGuide in spaceLayoutGuides[1...] {
layoutGuide.widthAnchor.constraint(equalTo: spaceLayoutGuides[0].widthAnchor, multiplier: 1.0).isActive = true;
}
layoutIfNeeded()
}
Expand All @@ -141,12 +137,12 @@ open class BubbleTabBar: UITabBar {
}
return button
}

@objc private func btnPressed(sender: CBTabBarButton) {
guard let index = buttons.index(of: sender),
index != NSNotFound,
let item = items?[index] else {
return
index != NSNotFound,
let item = items?[index] else {
return
}
buttons.forEach { (button) in
guard button != sender else {
Expand All @@ -160,7 +156,7 @@ open class BubbleTabBar: UITabBar {
}
delegate?.tabBar?(self, didSelect: item)
}

func select(itemAt index: Int, animated: Bool = false) {
guard index < buttons.count else {
return
Expand All @@ -181,5 +177,5 @@ open class BubbleTabBar: UITabBar {
self.container.layoutIfNeeded()
}
}

}
2 changes: 1 addition & 1 deletion BubbleTabBar/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.8.2</string>
<string>0.8.3</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
</dict>
Expand Down
4 changes: 4 additions & 0 deletions Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class ViewController: UIViewController {
tabBarController.viewControllers = [eventsVC, searchVC, activityVC, settingsVC]
tabBarController.tabBar.tintColor = #colorLiteral(red: 0.1579992771, green: 0.1818160117, blue: 0.5072338581, alpha: 1)
self.navigationController?.pushViewController(tabBarController, animated: true)

DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
tabBarController.selectedIndex = 2
}
}

override var preferredStatusBarStyle: UIStatusBarStyle {
Expand Down

0 comments on commit fdd7229

Please sign in to comment.