This is for the Tab1 code
Import SwiftUI
struct Tab1: View {
// MARK: - PROPERTIES
var headers: [Header] = headersData
var body: some View {
ScrollView(.vertical, showsIndicators: false) {
VStack(alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/, spacing: 20) {
// MARK: - HEADER
ScrollView(.horizontal, showsIndicators: false) {
HStack(alignment: .top, spacing: 0) {
ForEach(headers) { item in
HeaderView(header: item)
}
}
}
// MARK: - FOOTER
VStack(alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/, spacing: 20) {
Text("NYHETER")
.font(.system(.title, design: .serif))
.fontWeight(.bold)
.padding(8)
Text("UNDER ARBETE")
.font(.system(.body, design: .serif))
.multilineTextAlignment(.center)
.foregroundColor(Color.gray)
}
.frame(maxWidth: 640)
.padding()
.padding(.bottom, 8)
}
}
}
}
struct Tab1_Previews: PreviewProvider {
static var previews: some View {
Tab1(headers: headersData)
}
}
This is the tabview code:
struct ContentView: View {
@State private var selection = 0
var body: some View {
VStack {
TabView(selection: $selection) {
Tab1()
.tag(0)
Tab2()
.tag(1)
Tab3()
.tag(2)
Tab4()
.tag(3)
Tab5()
.tag(4)
}
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
Divider()
TabBarView(selection: $selection)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
and this is the code for the header itself
import SwiftUI
struct HeaderView: View {
// MARK - Properies
var header: Header
@State private var showHeadline: Bool = false
var slideInAnimation: Animation {
Animation.spring(response: 1.5, dampingFraction: 0.5, blendDuration: 0.5)
.speed(1)
.delay(0.25)
}
var body: some View {
ZStack{
Image(header.image)
.resizable()
.aspectRatio(contentMode: .fill)
HStack(alignment: .top, spacing: 0) {
VStack(alignment: .leading, spacing: 6) {
Text(header.headline)
.font(.system(.title, design: .serif))
.fontWeight(.bold)
.foregroundColor(.white)
.shadow(radius: 3)
Text(header.subheadline)
.font(.footnote)
.lineLimit(8)
.multilineTextAlignment(/*@START_MENU_TOKEN@*/.leading/*@END_MENU_TOKEN@*/)
.foregroundColor(.white)
.shadow(radius: 8)
}
.padding(.vertical, 0)
.padding(.horizontal, 20)
.frame(width: 281, height: 105)
.background(Color("ColorBlackTransparentLight"))
}
.frame(width: 285, height: 105, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
.offset(x:-150, y: showHeadline ? 110 : 220)
.animation(slideInAnimation)
.onAppear(perform: { self.showHeadline.toggle()
})
}
.frame(width: 480, height: 320, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
}
}
struct HeaderView_Previews: PreviewProvider {
static var previews: some View {
HeaderView(header: headersData[1])
.previewLayout(.sizeThatFits)
.environment(\.colorScheme, .dark)
}
}
Unfortunately adding the modifier above the tabView style didn’t work. Even adding the modifier in the HeaderView don´t change anything about the safearea.
EDIT:
this is the code for the TabView itself:
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 == "Inköpslista" && tabs[index].label == "Inköpslista" {
Image(systemName: tabs[index].image)
.frame(height: 20)
.rotationEffect(.degrees(15))
} 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: "Hem"),
Tab(image: "magnifyingglass", label: "Sök Recept"),
Tab(image: "leaf", label: "Skafferiet"),
Tab(image: "books.vertical.fill", label: "Mina Recept"),
Tab(image: "scroll", label: "Inköpslista")
]