Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 views
in Technique[技术] by (71.8m points)

tabitem - 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

    }
}
question from:https://stackoverflow.com/questions/66047257/tab-item-spacing-in-swiftui

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 ({

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...