0

When I run this code, the list is visible behind the tab bar created by the TabView. If I comment out the Image, everything is ok.

How do I make sure the list is not visible behind the tab bar?

struct MainView: View {
    var body: some View {
        TabView {
             ScheduleView()
                 .tabItem { Label ("Schedule", systemImage: "calendar") }
             ScheduleView()
                 .tabItem { Label ("Schedule", systemImage: "calendar") }
             ScheduleView()
                 .tabItem { Label ("Schedule", systemImage: "calendar") }
    
        
        }
    }
}

struct ScheduleView: View {
    @State var category = Categories.mixed
    
    var body: some View {
        VStack {
            HStack(alignment: .top) {
                Image("svrge-logo")
                    .resizable()
                    .scaledToFit()
                    .frame(height: 80)
                    .padding(.leading)
                Spacer()
                VStack(alignment: .trailing) {
                    Text ("Ver: 1.0")
                    Text ("nn matches")
                }
                .padding(.horizontal)
                .font(.caption)
            }
            
            Picker ("Gender", selection: $category) {
                ForEach(Categories.allCases) {
                    Text ($0.id).tag($0)
                }
            }
            .pickerStyle(SegmentedPickerStyle())
            
            List(filteredMatches(for: category)) { match in
                VStack {
                    HStack {
                        Text (match.matchNumber)
                        Spacer()
                        Text (match.date.toString(withFormat: "dd.MM.yyyy @ HH:mm"))
                    }
                    HStack {
                        Text (match.homeTeamName)
                        Spacer()
                        Text (match.awayTeamName)
                    }
                }
                
            }
            .listStyle(.plain)
        }
    }
}

enum Categories: String, Codable, CaseIterable, Identifiable {
    case womens
    case mens
    case mixed
    
    var id: String {
        return self.rawValue.capitalized
    }
}

var allMatches: [MatchInfo] = MatchInfo.data

func filteredMatches(for category: Categories) -> [MatchInfo] {
    return allMatches
        .filter { $0.category == category }
        .sorted()
}

let teamNames1 = (0...30).map{"Team \($0)"}
let teamNames2 = (31...60).map{"Team \($0)"}

struct MatchInfo: Identifiable, Comparable {
    var id: String { "\(season)-\(matchNumber)" }
    
    var season = "2022-2023"
    var matchNumber: String
    var date: Date = Date()

    var location = "Some Gym"
    var category:Categories = Categories.allCases.randomElement()!
    
    var homeTeamName = teamNames1.randomElement()!
    var awayTeamName = teamNames2.randomElement()!
    
    static func < (lhs: MatchInfo, rhs: MatchInfo) -> Bool {
        return lhs.date.timeIntervalSince(rhs.date) < 0
    }
    
    static func == (lhs: MatchInfo, rhs: MatchInfo) -> Bool {
        return lhs.date == rhs.date
    }
}
Zonker.in.Geneva
  • 1,389
  • 11
  • 19

0 Answers0