SwiftUI set Text and Image on TabbedView

Use the following code to set image and text both in TabbedView,

See this post for more info https://forums.developer.apple.com/thread/117472

TabbedView {
            tabOne()
                .tabItemLabel {
                    Image(systemName: "image1")
                    Text("Tab 1")
            }
            tabTwo()
                .tabItemLabel {
                    Image(systemName: "image2")
                    Text("Tab 2")
            }
        }

There is a workaround in iOS & iPadOS 13 Beta 2 Release Notes:

Workaround: Wrap the views you pass to the modifier in a VStack:

MyView()
    .tabItemLabel(VStack {
        Image("resourceName")
        Text("Item")
    })

Note that it's working for me using local images but not with SF Symbols (for example Image(systemName: "clock.fill") won't work).


Update:

This issue was fixed with Xcode 11 beta 3. tabItemLabel is renamed to tabItem and can be used like below:

.tabItem {
    Image(systemName: "plus")
    Text("Tab1")
}

In Xcode Beta 3, this has been fixed. Here is an example.

.tabItem {
    Image(systemName: "circle")
    Text("Hello")
}

Tags:

Ios

Swift

Swiftui