Search code examples
swiftuitabitem

Tab item spacing in Swiftui


Trying out the tabItem options and running into an issue....I am having some trouble spacing out the elements on my tab view. There is an extra long indent to the left before the first element.(see image) I came across a solution but I am not sure where to put it or if there is something better in SwiftUI: (tabBar.itemPositioning = .fill)

Help will be much appreciated. Thank you

Screenshot

==============

struct ContentView: View {
    @State var selected = 0
    var body: some View {
        TabView (selection: $selected){
            mainscreen()
            DayEntry().tabItem ({
                Image(systemName: "calendar.circle")
                Text("Home")
            }).tag(0)
           mainscreen()
                .tabItem ({
                    Image(systemName: "quote.bubble")
                    Text("Quote")
                }).tag(1)
            DayEntryVStacks()
                 .tabItem ({
                     Image(systemName: "gear")
                     Text("Settings")
                 }).tag(2)
            DayEntryVStacks()
                 .tabItem ({
                     Image(systemName: "calendar.badge.plus")
                     Text("Month")
                 }).tag(3)
        } .accentColor(.red)
        
        
   //     tabBar.itemPositioning = .fill

    }
}

Solution

  • There is an extra long indentation to the left before the first element

    It is not indentation you just did not add tab item for main screen, so it shows blank one for first view. So to fix this you have to add tab item:

        TabView (selection: $selected){
            mainscreen()
                            // << here !!
            DayEntry().tabItem ({