### Install via Swift Package Manager Source: https://github.com/unionst/union-tab-view/blob/main/Sources/UnionTabView/UnionTabView.docc/Articles/CustomViewsInLiquidGlassTabBars.md Add this URL to your project dependencies. ```text https://github.com/unionst/union-tab-view.git ``` -------------------------------- ### Tab Items with Notification Badges Source: https://context7.com/unionst/union-tab-view/llms.txt Add notification badges or custom indicators to tab items using SwiftUI's overlay capabilities. This example requires importing SwiftUI and UnionTabView. ```swift import SwiftUI import UnionTabView struct BadgeTabView: View { @State private var selectedTab: Tab = .home @State private var hasUnreadNotifications = true var body: some View { UnionTabView(selection: $selectedTab, tabs: [.home, .notifications, .profile]) { HomeView().unionTab(.home) NotificationsView().unionTab(.notifications) ProfileView().unionTab(.profile) } item: { tab, isSelected in if tab == .notifications { ZStack(alignment: .topTrailing) { Image(systemName: "bell.fill") .font(.title2) .foregroundStyle(isSelected ? .primary : .secondary) if hasUnreadNotifications { Circle() .fill(.red) .frame(width: 10, height: 10) .overlay { Circle().strokeBorder(.white, lineWidth: 2) } .offset(x: 4, y: -4) } } } else { Image(systemName: tab.icon) .font(.title2) .foregroundStyle(isSelected ? .primary : .secondary) } } } } ``` -------------------------------- ### Implement Custom Pill Selection Style Source: https://github.com/unionst/union-tab-view/blob/main/README.md Create a dynamic pill-shaped background that expands when a tab is selected. ```swift UnionTabView(selection: $selectedTab, tabs: RootTab.allCases) { // content... } item: { tab, isSelected in HStack(spacing: 6) { Image(systemName: tab.icon) .font(.system(size: 18, weight: .semibold)) if isSelected { Text(tab.title) .font(.system(size: 14, weight: .semibold)) } } .foregroundStyle(isSelected ? .white : .secondary) .padding(.horizontal, isSelected ? 16 : 12) .padding(.vertical, 10) .background { if isSelected { Capsule().fill(.blue.gradient) } } } ``` -------------------------------- ### Implement Basic UnionTabView Source: https://github.com/unionst/union-tab-view/blob/main/Sources/UnionTabView/UnionTabView.docc/Articles/CustomViewsInLiquidGlassTabBars.md Use UnionTabView to display custom views like profile pictures in the tab bar. ```swift import SwiftUI import UnionTabView enum Tab { case home case profile } struct ContentView: View { @State private var selectedTab: Tab = .home var body: some View { UnionTabView(selection: $selectedTab, tabs: [.home, .profile]) { HomeView().unionTab(.home) ProfileView().unionTab(.profile) } item: { tab, isSelected in if tab == .profile { Image("profile-pic") .resizable() .aspectRatio(contentMode: .fill) .frame(width: 32, height: 32) .clipShape(Circle()) .overlay { Circle() .strokeBorder( isSelected ? .blue : .clear, lineWidth: 2 ) } } else { Image(systemName: "house.fill") .font(.title2) .foregroundStyle(isSelected ? .primary : .secondary) } } } } ``` -------------------------------- ### Load Remote Profile Images Source: https://github.com/unionst/union-tab-view/blob/main/Sources/UnionTabView/UnionTabView.docc/Articles/CustomViewsInLiquidGlassTabBars.md Use AsyncImage to handle remote image loading within the tab bar item. ```swift AsyncImage(url: URL(string: "https://example.com/avatar.jpg")) { phase in switch phase { case .success(let image): image.resizable().aspectRatio(contentMode: .fill) case .failure, .empty: Image(systemName: "person.circle.fill") .resizable() .foregroundStyle(.gray) @unknown default: EmptyView() } } .frame(width: 32, height: 32) .clipShape(Circle()) ``` -------------------------------- ### Create an Icon-Only Tab Bar Source: https://github.com/unionst/union-tab-view/blob/main/README.md A minimal configuration using only system icons for tab items. ```swift UnionTabView(selection: $selectedTab, tabs: RootTab.allCases) { // content... } item: { tab, isSelected in Image(systemName: tab.icon) .font(.title2) .foregroundStyle(isSelected ? .blue : .gray) } ``` -------------------------------- ### Load Remote Profile Images in Tabs Source: https://context7.com/unionst/union-tab-view/llms.txt Uses AsyncImage to fetch and display profile pictures within a tab item, including success and failure states. ```swift import SwiftUI import UnionTabView struct RemoteImageTabView: View { @State private var selectedTab: Tab = .home let profileImageURL = URL(string: "https://example.com/avatar.jpg") var body: some View { UnionTabView(selection: $selectedTab, tabs: [.home, .profile]) { HomeView().unionTab(.home) ProfileView().unionTab(.profile) } item: { tab, isSelected in if tab == .profile { AsyncImage(url: profileImageURL) { phase in switch phase { case .success(let image): image .resizable() .aspectRatio(contentMode: .fill) case .failure, .empty: Image(systemName: "person.circle.fill") .resizable() .foregroundStyle(.gray) @unknown default: EmptyView() } } .frame(width: 32, height: 32) .clipShape(Circle()) .overlay { Circle() .strokeBorder(isSelected ? .blue : .clear, lineWidth: 2) } } else { Image(systemName: "house.fill") .font(.title2) .foregroundStyle(isSelected ? .primary : .secondary) } } } } ``` -------------------------------- ### Create custom profile picture tab items Source: https://context7.com/unionst/union-tab-view/llms.txt Use custom SwiftUI views, such as images or profile pictures, within the tab item builder. ```swift import SwiftUI import UnionTabView enum Tab { case home case profile } struct ContentView: View { @State private var selectedTab: Tab = .home var body: some View { UnionTabView(selection: $selectedTab, tabs: [.home, .profile]) { HomeView().unionTab(.home) ProfileView().unionTab(.profile) } item: { tab, isSelected in if tab == .profile { // Custom profile picture Image("profile-pic") .resizable() .aspectRatio(contentMode: .fill) .frame(width: 32, height: 32) .clipShape(Circle()) .overlay { Circle() .strokeBorder( isSelected ? .blue : .clear, lineWidth: 2 ) } } else { Image(systemName: "house.fill") .font(.title2) .foregroundStyle(isSelected ? .primary : .secondary) } } } } ``` -------------------------------- ### Implement UnionTabView in a View Source: https://github.com/unionst/union-tab-view/blob/main/README.md Basic implementation using a selection binding and custom tab item rendering. ```swift import UnionTabView enum Tab { case home, settings } struct ContentView: View { @State private var tab: Tab = .home var body: some View { UnionTabView(selection: $tab, tabs: [.home, .settings]) { Text("Home").unionTab(Tab.home) Text("Settings").unionTab(Tab.settings) } item: { tab, isSelected in Image(systemName: tab == .home ? "house.fill" : "gear") .foregroundStyle(isSelected ? .primary : .secondary) } } } ``` -------------------------------- ### Animated Tab Selection with Symbol Effects Source: https://context7.com/unionst/union-tab-view/llms.txt Use SwiftUI animations and symbol effects to provide visual feedback when tabs are selected. Requires importing SwiftUI and UnionTabView. ```swift import SwiftUI import UnionTabView struct AnimatedTabView: View { @State private var selectedTab: Tab = .home var body: some View { UnionTabView(selection: $selectedTab, tabs: Tab.allCases) { ForEach(Tab.allCases, id: \.self) { tab in Text("\(tab.title) Content") .unionTab(tab) } } item: { tab, isSelected in VStack(spacing: 6) { Image(systemName: tab.icon) .font(.system(size: 22)) .symbolEffect(.bounce, value: isSelected) Circle() .fill(isSelected ? .blue : .clear) .frame(width: 5, height: 5) } .foregroundStyle(isSelected ? .blue : .secondary) } } } ``` -------------------------------- ### Add Animated Selection Effects Source: https://github.com/unionst/union-tab-view/blob/main/README.md Integrate symbol effects to animate tab items upon selection. ```swift UnionTabView(selection: $selectedTab, tabs: RootTab.allCases) { // content... } item: { tab, isSelected in VStack(spacing: 6) { Image(systemName: tab.icon) .font(.system(size: 22)) .symbolEffect(.bounce, value: isSelected) Circle() .fill(isSelected ? .blue : .clear) .frame(width: 5, height: 5) } .foregroundStyle(isSelected ? .blue : .secondary) } ``` -------------------------------- ### Define Tabs with TabItem Protocol Source: https://context7.com/unionst/union-tab-view/llms.txt Uses a structured enum to define tab configurations, including icons for active and inactive states. ```swift import SwiftUI import UnionTabView // Define a tab type conforming to TabItem protocol enum AppTab: String, CaseIterable, Hashable { case home = "Home" case notifications = "Notifications" case settings = "Settings" var icon: String { switch self { case .home: return "house.fill" case .notifications: return "bell.fill" case .settings: return "gearshape.fill" } } var inactiveIcon: String { switch self { case .home: return "house" case .notifications: return "bell" case .settings: return "gearshape" } } } struct TabItemExample: View { @State private var selectedTab: AppTab = .home var body: some View { UnionTabView(selection: $selectedTab, tabs: AppTab.allCases.map { $0 }) { ForEach(AppTab.allCases, id: \.self) { tab in Text("\(tab.rawValue) View") .unionTab(tab) } } item: { tab, isSelected in VStack(spacing: 4) { Image(systemName: isSelected ? tab.icon : tab.inactiveIcon) .font(.title3) Text(tab.rawValue) .font(.system(size: 10, weight: .medium)) } .foregroundStyle(isSelected ? .primary : .secondary) } } } ``` -------------------------------- ### Create Full-Width Tab Bars Source: https://context7.com/unionst/union-tab-view/llms.txt Applies frame(maxWidth: .infinity) to tab item views to ensure the tab bar spans the entire screen width. ```swift import SwiftUI import UnionTabView struct FullWidthTabView: View { @State private var selectedTab: Tab = .home var body: some View { UnionTabView(selection: $selectedTab, tabs: Tab.allCases) { ForEach(Tab.allCases, id: \.self) { tab in Text("\(tab.title) Content") .unionTab(tab) } } item: { tab, isSelected in VStack(spacing: 4) { Image(systemName: tab.icon) .font(.title2) Text(tab.title) .font(.system(size: 10, weight: .medium)) } .foregroundStyle(isSelected ? .primary : .secondary) .frame(maxWidth: .infinity) // Makes tab bar span full width } } } ``` -------------------------------- ### Implement UnionTabView with custom labels Source: https://context7.com/unionst/union-tab-view/llms.txt Use UnionTabView to create a tabbed interface with custom icons and labels for each tab. ```swift import SwiftUI import UnionTabView enum RootTab: Hashable { case home case search case profile } struct ContentView: View { @State private var selectedTab: RootTab = .home var body: some View { UnionTabView(selection: $selectedTab, tabs: [.home, .search, .profile]) { NavigationStack { HomeView() } .unionTab(.home) NavigationStack { SearchView() } .unionTab(.search) NavigationStack { ProfileView() } .unionTab(.profile) } item: { tab, isSelected in VStack(spacing: 4) { Image(systemName: tabIcon(for: tab)) .font(.title2) Text(tabTitle(for: tab)) .font(.system(size: 10, weight: .medium)) } .foregroundStyle(isSelected ? .primary : .secondary) } } func tabIcon(for tab: RootTab) -> String { switch tab { case .home: return "house.fill" case .search: return "magnifyingglass" case .profile: return "person.fill" } } func tabTitle(for tab: RootTab) -> String { switch tab { case .home: return "Home" case .search: return "Search" case .profile: return "Profile" } } } ``` -------------------------------- ### Create Full-Width Tab Bar Source: https://github.com/unionst/union-tab-view/blob/main/Sources/UnionTabView/UnionTabView.docc/Articles/CustomViewsInLiquidGlassTabBars.md Apply .frame(maxWidth: .infinity) to the tab item views to expand the tab bar across the full width. ```swift UnionTabView(selection: $selectedTab, tabs: tabs) { // content... } item: { tab, isSelected in VStack { Image(systemName: tab.icon) Text(tab.title) } .frame(maxWidth: .infinity) // Makes tab bar full-width } ``` -------------------------------- ### Custom Pill-Style Tab Items Source: https://context7.com/unionst/union-tab-view/llms.txt Implement expanding pill-shaped tab items that reveal labels only when selected. This provides a modern navigation experience. Ensure SwiftUI and UnionTabView are imported. ```swift import SwiftUI import UnionTabView struct PillStyleTabView: View { @State private var selectedTab: Tab = .home var body: some View { UnionTabView(selection: $selectedTab, tabs: Tab.allCases) { ForEach(Tab.allCases, id: \.self) { tab in TabContentView(tab: tab) .unionTab(tab) } } item: { tab, isSelected in HStack(spacing: 6) { Image(systemName: tab.icon) .font(.system(size: 18, weight: .semibold)) if isSelected { Text(tab.title) .font(.system(size: 14, weight: .semibold)) } } .foregroundStyle(isSelected ? .white : .secondary) .padding(.horizontal, isSelected ? 16 : 12) .padding(.vertical, 10) .background { if isSelected { Capsule().fill(.blue.gradient) } } } } } ``` -------------------------------- ### Add Notification Badge to Tab Source: https://github.com/unionst/union-tab-view/blob/main/Sources/UnionTabView/UnionTabView.docc/Articles/CustomViewsInLiquidGlassTabBars.md Embed a ZStack within the item closure to overlay notification indicators on tab icons. ```swift item: { tab, isSelected in if tab == .profile { ZStack(alignment: .topTrailing) { Image("profile-pic") .resizable() .aspectRatio(contentMode: .fill) .frame(width: 32, height: 32) .clipShape(Circle()) .overlay { Circle() .strokeBorder(isSelected ? .blue : .clear, lineWidth: 2) } if hasUnreadNotifications { Circle() .fill(.red) .frame(width: 10, height: 10) .overlay { Circle().strokeBorder(.white, lineWidth: 2) } .offset(x: 2, y: -2) } } } else { Image(systemName: tab.icon) .font(.title2) .foregroundStyle(isSelected ? .primary : .secondary) } } ``` -------------------------------- ### Apply .unionTab(_:) modifier Source: https://context7.com/unionst/union-tab-view/llms.txt Apply the .unionTab modifier to each content view to register it with the parent UnionTabView. ```swift import SwiftUI import UnionTabView enum Tab: Hashable { case home case settings } struct MyApp: View { @State private var tab: Tab = .home var body: some View { UnionTabView(selection: $tab, tabs: [.home, .settings]) { // Apply .unionTab() to each content view HomeView() .unionTab(.home) SettingsView() .unionTab(.settings) } item: { tab, isSelected in Image(systemName: tab == .home ? "house.fill" : "gear") .foregroundStyle(isSelected ? .primary : .secondary) } } } ``` -------------------------------- ### Apply the .unionTab() Modifier Source: https://github.com/unionst/union-tab-view/blob/main/README.md Use this modifier on content views to manage safe area spacing and hide the system tab bar on supported iOS versions. ```swift NavigationStack { HomeView() } .unionTab(RootTab.home) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.