Skip to content
Tabbed Header preview
Rendered from the SwiftUI source on this page.

Tabbed Header

From syxUI — written for both platforms, not translated between them.

A title with underline-style horizontal tabs.

Navigation · SwiftUI · iOS 17

  • navigation
  • swiftui

The actual source

HeaderTabs.swift
// Tabbed Header · syxUI · https://syxui.dev/components/hdr-tabs
// Free in any project. Keep this line and credit syxUI where a person can read it.

import SwiftUI

let hdrBlue = Color(red: 0.0, green: 0.47, blue: 1.0)

// Title with underline tabs
struct HeaderTabs: View {
    @State private var sel = 0
    let tabs = ["For You", "Following", "Trending"]
    var body: some View {
        VStack(alignment: .leading, spacing: 0) {
            Text("Discover").font(.system(size: 28, weight: .bold)).padding(.bottom, 12)
            HStack(spacing: 22) {
                ForEach(Array(tabs.enumerated()), id: \.offset) { i, t in
                    VStack(spacing: 7) {
                        Text(t).font(.system(size: 15, weight: sel == i ? .semibold : .regular)).foregroundStyle(sel == i ? Color.primary : .secondary)
                        Capsule().fill(sel == i ? hdrBlue : .clear).frame(height: 2.5)
                    }.fixedSize()
                }
                Spacer()
            }
        }.frame(width: 340)
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17