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 #customtabbar #customtabview #ios #library #swift #swiftui #tab #tabbar #tabview #uitabbar #uitabbarcontroller #view #xcode
YOU MIGHT ALSO LIKE...
CameraBackground

Features Both front and back camera supported. Flash modes: auto, on, off. Countdown timer. Tap to focus. Pinch to zoom. Usage  

DKCamera

Description A light weight & simple & easy camera for iOS by Swift. It uses CoreMotion framework to detect device orientation, so ...

HorizonSDK-iOS

Horizon SDK is a state of the art real-time video recording / photo shooting iOS library. Some of the features ...

LLSimpleCamera

LLSimpleCamera: A simple customizable camera - video recorder control LLSimpleCamera is a library for creating a customized camera - video ...

RSBarcodes_Swift

RSBarcodes allows you to read 1D and 2D barcodes using the metadata scanning capabilities introduced with iOS 7 and generate ...