Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI set Text and Image on TabbedView

Tags:

ios

swift

swiftui

In the documentation for TabbedView it says you can add both a Text and an Image View by using a LayoutView. I'm unable to find any reference to LayoutView anywhere.

This works:

.tabItemLabel(Image("image"))

And this works:

.tabItemLabel(Text("image"))

How can I show both like UITabBarItem does?

like image 454
Micah Wilson Avatar asked Jun 07 '19 05:06

Micah Wilson


2 Answers

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

.tabItem {
    Image(systemName: "circle")
    Text("Hello")
}
like image 54
avanalfen Avatar answered Nov 15 '22 03:11

avanalfen


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")
            }
        }
like image 28
AtulParmar Avatar answered Nov 15 '22 04:11

AtulParmar