Component

Custom Tab Bar

Learn to add Custom Tab Bar to your iOS App (Supports Xcode 16 and iOS 18)

Custom Tab Bar

Steps to Create a Custom Tab Bar:

1. Set Up the Tab Bar Structure:

import SwiftUI

struct CustomTabBarView: View {
    @State private var selectedTab = 0
    let tabBarItems = ["house.fill", "magnifyingglass", "person.fill"]

    var body: some View {
        VStack {
            Spacer()

            // Main Content
            TabView(selection: $selectedTab) {
                HomeView().tag(0)
                SearchView().tag(1)
                ProfileView().tag(2)
            }

            // Custom Tab Bar
            HStack {
                ForEach(0..<tabBarItems.count, id: \.self) { index in
                    Spacer()

                    Button(action: {
                        withAnimation(.spring()) {
                            selectedTab = index
                        }
                    }) {
                        VStack {
                            Image(systemName: tabBarItems[index])
                                .font(.system(size: 24))
                                .foregroundColor(selectedTab == index ? .blue : .gray)
                                .scaleEffect(selectedTab == index ? 1.2 : 1.0) // Add animation for scaling

                            Text(tabName(for: index))
                                .font(.caption)
                                .foregroundColor(selectedTab == index ? .blue : .gray)
                        }
                        .padding(.vertical, 10)
                    }

                    Spacer()
                }
            }
            .padding(.bottom, 20)
            .background(Color.white.shadow(radius: 10))
        }
    }

    func tabName(for index: Int) -> String {
        switch index {
        case 0: return "Home"
        case 1: return "Search"
        case 2: return "Profile"
        default: return ""
        }
    }
}

struct HomeView: View {
    var body: some View {
        Text("Home Screen")
            .font(.largeTitle)
            .foregroundColor(.blue)
    }
}

struct SearchView: View {
    var body: some View {
        Text("Search Screen")
            .font(.largeTitle)
            .foregroundColor(.green)
    }
}

struct ProfileView: View {
    var body: some View {
        Text("Profile Screen")
            .font(.largeTitle)
            .foregroundColor(.purple)
    }
}

Time to build your iOS App?

ShipiOS provides you SwiftUI boilerplate, How-to Guides, Components Library and extra rewards!

Get ShipiOS Package
ShipiOS.App

I told you it's more than just a boilerplate :)

Made with ❤️ on 🌍

Need help? Reach out on:

© Copyright 2024 ShipiOS.App - All rights reserved.