πŸ“± TabBar – highly customizable tab bar for your SwiftUI application.

Overview

TabBar

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

    var body: some View {
        TabBar(selection: $selection) {
            Text("First")
                .tabItem(for: Item.first)

            Text("Second")
                .tabItem(for: Item.second)

            Text("Third")
                .tabItem(for: Item.third)
        }
    }
}

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:

Contribution

If you struggle with something feel free to open an issue. Pull requests are also appreciated.

License

TabBar is under the terms and conditions of the MIT license.

MIT License

Copyright (c) 2021 Tamerlan Satualdypov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Comments
  • TabBar content did not appear (render) in iOS14.0

    TabBar content did not appear (render) in iOS14.0

    In iOS14.0, I use TabBar in a NavigationView, content of the tabbar is invisible, but CustomTabBarStyle works.Without NavigationView, all things go well.

    question 
    opened by Ccapton 6
  • Hide/Show TabBar

    Hide/Show TabBar

    hey, great work really. Is it possible to hide the navbar? (remove from screen)| The idea is when a user clicks on a navigation button and go to another view the navbar should fall down and when the user click on Back button it should appear again.

    enhancement 
    opened by onisiforos7 5
  • Issue #1 - Hide/Show TabBar

    Issue #1 - Hide/Show TabBar

    Hey! I find your TabBar very cool and felt like contributing something to it. I'm still pretty new to Swift, so my solution may not be the prettiest. Have a look over it and tell me what you think. πŸ˜‰

    Changes

    • Implemented a visibility property that can be used to hide the TabBar on demand

    • Adapted the example code to showcase new functionality

    • Adapted README according to new example code

    enhancement 
    opened by bgeisb 0
  • How to hide tabor dynamically

    How to hide tabor dynamically

    Is it possible to hide tab bar when user selects second tab item only, for example? I want to have several items and if selects first item tabbar should be show but for another (or navigation links) - not.

    question 
    opened by st-small 1
  • It seems the page will be recreated when switch between tabs each time.

    It seems the page will be recreated when switch between tabs each time.

    struct ContentView: View {
        
        private enum Item: Int, Tabbable {
            case first = 0
            case second
            case third
            
            var icon: String {
                switch self {
                    case .first: return "house"
                    case .second: return "magnifyingglass"
                    case .third: return "person"
                }
            }
            
            var title: String {
                switch self {
                    case .first: return "First"
                    case .second: return "Second"
                    case .third: return "Third"
                }
            }
        }
        
        @State private var selection: Item = .first
        @State private var visibility: TabBarVisibility = .visible
        
        var body: some View {
            TabBar(selection: $selection, visibility: $visibility) {
                Button {
                    withAnimation {
                        visibility.toggle()
                    }
                } label: {
                    Text("Hide/Show TabBar")
                }
                .tabItem(for: Item.first)
                
    			Second()
                    .tabItem(for: Item.second)
                
                Text("Third")
                    .tabItem(for: Item.third)
            }
            .tabBar(style: CustomTabBarStyle())
            .tabItem(style: CustomTabItemStyle())
        }
    }
    
    struct ContentSystemTabView: View {
    	var body: some View {
    		TabView {
    			Text("First")
    				.tabItem {
    					Text("first")
    				}
    
    			Second()
    				.tabItem {
    					Text("second")
    				}
    		}
    	}
    }
    
    struct Second: View {
    	init() {
    		print("init...")
    	}
    	var body: some View {
    		Text("Second")
    	}
    }
    

    You will find the difference between TabView.

    enhancement help wanted 
    opened by Horse888 2
Owner
Tamerlan Satualdypov
Left brain for code, right brain for design. Self-educated iOS developer from Kazakhstan. Love open source.
Tamerlan Satualdypov
TabDrawer is a customizable TabBar UI element that allows you to run a block of code upon TabBarItem selection

TabDrawer TabDrawer is a customizable TabBar UI element that allows you to run a block of code upon TabBarItem selection, or display a customizable dr

Winslow DiBona 503 Oct 5, 2022
Full Customizable Tabbar with IBInspectables

BEKCurveTabbar Full Customizable Tabbar with IBInspectables A fun replacement for UITabbar. The Component uses BΓ©zier paths. Demo Example usage: You c

Behrad Kazemi 169 Dec 5, 2022
Aesthetic floating tab bar ––– SwiftUI & Combine ⛓️ Importable via Swift Package Manager πŸ“¦

FloatingTabBar An aesthetic floating tab bar made with SwiftUI & Combine importabable via Swift Package Manager ?? Based off BottomBar-SwiftUI Preview

10011.co 135 Jan 8, 2023
A prototype of custom tab bar using SwiftUI with techniques of mask + matchedGeometryEffect

SliderTabBar A prototype of custom tab bar using SwiftUI with techniques of mask

Ka Kui 1 Dec 24, 2021
Aesthetic floating tab bar ––– SwiftUI & Combine ⛓️ Importable via Swift Package Manager πŸ“¦

FloatingTabBar An aesthetic floating tab bar made with SwiftUI & Combine importabable via Swift Package Manager ?? Based off BottomBar-SwiftUI Preview

10011.co 134 Jan 5, 2023
A fun, easy-to-use tab bar navigation controller for iOS.

CircleBar Don’t you, sometimes, miss fun user interfaces? Truth is, we do. Sure, you can't use them in enterprise apps for obvious reasons, but if you

softhaus 786 Dec 25, 2022
Different Styles of Custom Tab Bar

LightCardTabBar An expiremental project exploring different types of custom-tabbar styles, screenshots as below. Screenshots Implementation The implem

Hussein Ryalat 31 Dec 23, 2022
Simplistic & unfinished recreation of MobileSafari's tab bar

SafariTabBar This is a simplistic recreation of the MobileSafari tab bar on iPad (prior to iPadOS 15). It is also very unfinished, and not intended in

Steven Troughton-Smith 51 Oct 26, 2022
A custom tab bar controller for iOS.

ESTabBarController ESTabBarController is a custom tab bar controller for iOS. It has a tab indicator that moves animated along the bar when switching

null 122 Oct 6, 2022
Another UITabBar & UITabBarController (iOS Tab Bar) replacement, but uses Auto Layout for arranging it's views hierarchy.

GGTabBar GGTabBar is a simple UITabBar & UITabBarController replacement that uses Auto Layout for constructing the GUI. I created it for curiosity, bu

Nicolas Goles 157 Sep 26, 2022
Emoji Tab Bar button badges ✨

SuperBadges Add emojis and colored dots as badges for your Tab Bar buttons ✨ Usage Add an emoji badge: YourTabBarController.addDotAtTabBarItemIndex(

Oded Harth 55 Dec 13, 2021
A custom tab bar controller for iOS written in Swift 4.2

A custom tab bar controller for iOS written in Swift 4.0 Screenshots Installation Cocoa Pods: pod 'AZTabBar' Swift Package Manager: You can use The Sw

Antonio Zaitoun 335 Dec 11, 2022
πŸ“± A minimal tab bar alternative

MiniTabBar A clean simple alternative to the UITabBar. Only shows the title when being tapped on. Gives the app a way cleaner look :) Requirements iOS

Dylan Marriott 155 Dec 20, 2022
CustomUI in SwiftUI - Full Native Custom SwiftUI NavBar, TabBar, SearchBar, Dark mode, a little bit animations

CustomUI_in_SwiftUI Full Native Custom SwiftUI NavBar, TabBar, SearchBar, Dark m

Alexander Ryakhin 1 Jun 5, 2022
ESTabBarController is a highly customizable TabBarController component, which is inherited from UITabBarController.

ESTabBarController is a highly customizable TabBarController component, which is inherited from UITabBarController. Why? In real-world developmen

Vincent Li 4.9k Jan 5, 2023
RAMAnimatedTabBarController is a Swift UI module library for adding animation to iOS tabbar items and icons. iOS library made by @Ramotion

ANIMATED TAB BAR Swift UI module library for adding animation to iOS tabbar items and icons.

Ramotion 11k Jan 8, 2023
A lightweight customized tabbar view. πŸ“Œ

A lightweight customized tabbar view. Screenshots Features Installation Setup ToDos Credits Thanks License Screenshots Features Easily Configurable an

Hemang 137 Dec 16, 2022
A curved tabbar with a center button

WHTabbar A very simple solution to implement center button in your native UITabbar. Example To run the example project, clone the repo, and run pod in

wajeehulhassan 18 Dec 4, 2022
Customisable iOS bottom menu works like Tabbar

SSCustomTabMenu Simple customizable iOS bottom menu works like Tabbar, in Swift. Features Simple and customizable iOS Tab Menu items, in Swift. Requir

Simform Solutions 81 Aug 3, 2022