TabBar
  • December 2, 2023

SwiftUI standard TabView component is not so flexible and to customize it you have to modify appearance proxy of UITabBar or implement your own one from scratch. The goal of this library is to solve this problem.

Table of contents


Requirements


  • SwiftUI
  • iOS 13.0 or above

Installation


TabBar is available through Swift Package Manager

Swift Package Manager

In Xcode select:

File > Swift Packages > Add Package Dependency…

Then paste this URL:

https://github.com/onl1ner/TabBar.git

Usage


To start using TabBar you have to create an enum which will implement Tabbable protocol:

enum Item: Int, Tabbable {
case first = 0
case second
case third

var icon: String {
switch self {
case .first: // Name of icon of first item.
case .second: // Name of icon of second item.
case .third: // Name of icon of third item.
}
}

var title: String {
switch self {
case .first: // Title of first item.
case .second: // Title of second item.
case .third: // Title of third item.
}
}
}

After that you will be able to create TabBar instance:

struct ContentView: View {
@State private var selection: Item = .first
@State private var visibility: TabBarVisibility = .visible

var body: some View {
TabBar(selection: $selection, visibility: $visibility) {
Text(“First”)
.tabItem(for: Item.first)

Text(“Second”)
.tabItem(for: Item.second)

Text(“Third”)
.tabItem(for: Item.third)
}
.tabBar(style: CustomTabBarStyle())
.tabItem(style: CustomTabItemStyle())
}
}

After these actions tab bar with default style will be created.

Customization

TabBar component is highly customizable. This is achieved by introducing TabBarStyle and TabItemStyle protocols. By implementing each of the protocol you will be able to build your custom tab bar. NOTE that TabBar automaticaly pushes down to bottom any of tab bar styles.

After creating your custom styles you may inject them to your tab bar by using tabBar(style:) and tabItem(style:) functions. Here is the showcase of default style and one of the examples of what you can achieve by customizing tab bar:

GitHub


View Github

#bar #ios #library #swift #swiftui #tab #tabbar #uitabbar #uitabbarcontroller #view #xcode
YOU MIGHT ALSO LIKE...
🧭 NavigationKit

NavigationKit is a lightweight library which makes SwiftUI navigation super easy to use. 💻 Installation 📦 Swift Package Manager Using Swift Package Manager, add ...

swiftui-navigation-stack

An alternative SwiftUI NavigationView implementing classic stack-based navigation giving also some more control on animations and programmatic navigation. NavigationStack Installation ...

Stinsen

Simple, powerful and elegant implementation of the Coordinator pattern in SwiftUI. Stinsen is written using 100% SwiftUI which makes it ...

SwiftUI Router

With SwiftUI Router you can power your SwiftUI app with path-based routing. By utilizing a path-based system, navigation in your app becomes ...

FlowStacks

This package takes SwiftUI's familiar and powerful NavigationStack API and gives it superpowers, allowing you to use the same API not just ...