Skip to content

Instantly share code, notes, and snippets.

@chriseidhof
Created July 13, 2020 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriseidhof/b6dad3180e1d12be8919d1759bf7de3b to your computer and use it in GitHub Desktop.
Save chriseidhof/b6dad3180e1d12be8919d1759bf7de3b to your computer and use it in GitHub Desktop.
//
// ContentView.swift
// TabBar
//
// Created by Chris Eidhof on 13.07.20.
//
import SwiftUI
struct ContentView: View {
let tabs: [Text] = [
Text("World Clock"),
Text("Alarm"),
Text("Bedtime")
]
@State var selectedTabIndex = 0
@Namespace var ns
var body: some View {
HStack(alignment: .top) {
ForEach(tabs.indices) { tabIndex in
VStack {
Button(action: {
withAnimation(.default) {
self.selectedTabIndex = tabIndex
}
}, label: { self.tabs[tabIndex] }).padding(.bottom, 4)
.overlay(Group {
if selectedTabIndex == tabIndex {
VStack {
Spacer()
Rectangle()
.fill(Color.accentColor)
.matchedGeometryEffect(id: "indicator", in: ns)
.frame(height: 2, alignment: .bottom)
}
}
})
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment