Hi! So i’ve been able to code an working tabBar for my app, and now i really want to go in to each section at the tabBar to add content to the pages. Is it possible to start a new file ”contentview” and then code for let’s say for example ”home” or does the code have to share with my current TabCode? And how can i make them separate?
import SwiftUI
struct TabBarView: View {
@Binding var selection: Int
@Namespace private var currentTab
var body: some View {
HStack(alignment: .bottom) {
ForEach(tabs.indices) { index in
GeometryReader { geometry in
VStack(spacing: 4) {
if selection == index {
Color(.label)
.frame(height: 2)
.offset(y: -8)
.matchedGeometryEffect(id: "currentTab", in: currentTab)
if tabs[selection].label == "Sparade Recept" && tabs[index].label == "Sparade Recept" {
Image(systemName: tabs[index].image)
.frame(height: 20)
.rotationEffect(.degrees(25))
} else {
Image(systemName:tabs[index].image)
.frame(height: 20)
}
Text(tabs[index].label)
.font(.caption2)
.fixedSize()
}
.fixedSize(horizontal: false, vertical: true)
.frame(width: geometry.size.width / 2, height: 44, alignment: .bottom)
.padding(.horizontal)
.foregroundColor(selection == index ? Color(.label) : .secondary)
.onTapGesture {
withAnimation {
selection = index
}
}
}
.frame(height: 44, alignment: .bottom)
struct TabBarView_Previews: PreviewProvider {
static var previews: some View {
TabBarView(selection: Binding.constant(0))
.previewLayout(.sizeThatFits)
struct Tab {
let image: String
let label: String
}
let tabs = [
Tab(image: "house", label: "Startsida"),
Tab(image: "hare", label: "Animaliskt"),
Tab(image: "magnifyingglass", label: "Sök Recept"),
Tab(image: "leaf", label: "Vegetariskt"),
Tab(image: "books.vertical.fill", label: "Mina Recept")
]