SwiftUI: Tabview Repeating itself

IvanFernand

I'm trying to create a tabview for a macOS 10.15 app.

 TabView {      
        BookmarksView()
            .tabItem {
            Text("Bookmark Settings")
        }
    
    DisplaySettings()
        .tabItem {
            Text("Display Settings")
        }
}
     

And in any of my views included in the tab that has one element in the body it renders properly in the tab view.

struct BookmarksView: View {
    var body: some View {
        Text("Bookmarks View")
           .font(.title)
           .font(Font.body.bold())
             
    }
}

enter image description here

But if i add any other element in the view, the tab repeats and shows the added element in its own tab.

struct BookmarksView: View {
        var body: some View {
            Text("Bookmarks View")
               .font(.title)
               .font(Font.body.bold())

             Text("Testing")
               .font(.system(size: 15))
                  
        }
    }

enter image description here

Asperi

Try to wrap them in container (stack or something) explicitly, like

struct BookmarksView: View {
    var body: some View {
        VStack {                   // << this !!
          Text("Bookmarks View")
            .font(.title)
            .font(Font.body.bold())

          Text("Testing")
            .font(.system(size: 15))
        }               
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related