Fully customizable tabbar controller.
- Cusom tabbar view. No limitations.
- Standart
UIViewController
lifecycle for child controllers. - Preserve child controllers across selection.
- Hide/Show tabbar view.
- Cocoa-like API. UIKit support.
- Create custom tabbar view
class MyTabBarView: UIView {
// Should be called on every selected tab change.
var onItemSelect: (Int) -> Void
// Current selected tab index.
var selectedIndex: Int
// Layout tab bar view items.
}
Note: Above provided one of possible API. You are not limited to use delegate or other patterns.
- Create custom tabbar controller
import TabBarController
class MyTabBarController: TabBarController {
// Provide your root controllers.
override var controllers: [UIViewController] { myChildControllers }
// Provide your tabbar view.
override var tabBarView: UIView { myTabBarView }
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(myTabBarView)
// Add contraints for tabbar view or layout it other way.
// Show corresponding child controller on tabbar view selection change.
myTabBarView.onItemSelect = { [weak self] selectedIndex in
self?.selectedIndex = seelctedIndex
}
}
// Update tabbar view state on programmatically selected tab chage.
override func selectedIndexDidChange() {
super.selectedIndexDidChange()
myTabBarView.selectedIndex = selectedIndex
}
}
- Use
MyTabBarController
as default tabbar controller.
let controller = MyTabBarController()
controller.myChildControllers = [...]
window?.rootViewContoller = controller
- (Optional, but handy) To make
MyTabBarContoller
accessible from everyUIViewController
just like defaultUITabBarController
:
extension UIViewController {
var myTabBarController: MyTabBarController? {
findParent(type: MyTabBarController.self)
}
}
So from any view controller:
myTabBarController.setTabBarVisibility(isHidden: true)
The implementation is super lightweight. TabBarController
inherits UIViewController
and doesn't use UITabBarController
under the hood.
- Swift 5.0
- iOS 15.0
dependencies: [
.package(
url: "https://github.com/MobileUpLLC/TabBarController",
.upToNextMajor(from: "1.0.0")
)
]
TabBarController is destributed under the MIT license.