Huge black bars on top and bottom of UI - SwiftUI

Viewed 41

I have an issue with Views in the sample app I am trying to help me learn SwiftUI views. The black bars at the top and bottom shouldn't be there. I want to extend the view to the top and bottom of the safe area limit.

Here is the code using Xcode 13.4.1 and iOS 15.5:

import SwiftUI

struct ContentView: View {
    var body: some View {
        TabView {
            HotelView()
                .tabItem {
                    Image(systemName: "house")
                        .resizable()
                    Text("Home")
                }
            HomeView(title: "My Trips")
                .tabItem {
                    Image(systemName: "suitcase")
                    Text("My Trips")
                }
            HomeView(title: "Saved")
                .tabItem {
                    Image(systemName: "heart")
                    Text("Saved")
                }
            HomeView(title: "Profile")
                .tabItem {
                    Image(systemName: "person")
                    Text("Profile")
                }
        }
        .frame(maxWidth: .infinity, maxHeight: .infinity)
    }
}

Also the HotelView file:

import SwiftUI


struct HotelView: View {
    
    var body: some View {
        NavigationView {
            List(hotels) {  hotel in
                ScrollView(.vertical, showsIndicators: true) {
                    NavigationLink(destination: DetailView(hotels: hotel)) {
                        HStack {
                            Image(hotel.image)
                                .resizable()
                                .frame(height: 100)
                                .frame(maxWidth: .infinity)
                                .clipShape(RoundedRectangle(cornerRadius: 10, style: .continuous))
                                .overlay(
                                    Text(hotel.city)
                                        .fontWeight(.bold)
                                        .foregroundColor(.white),alignment: .center)
                            
                            
                        }
                    }
                }
            }
            // navtitle
        }
    }
}

And the result in the simulator is: Black bars on top and bottom

import SwiftUI

@main
struct Mohsin_city_plannerApp: App {
    var body: some Scene {
        WindowGroup {

                ContentView()
            
            
        }
    
    }
}
1 Answers

Need to add launch screen to your info.plist

So the solution is to add launch screen to your plist info file even in SwiftUINo more black bars!!

Related