TabView images on macOS

I can't seem to get the SwiftUI TabView images to work on macOS, no matter what I try. I've tried different images, image sizes, etc. I've also swapped the Image/Text order in the .tabItem, and tried wrapping it in a VStack/Group.
Are they just not working?


struct PlaygroundView: View {
  @State private var selectedTab: Int = 0

  var body: some View {
    TabView(selection: $selectedTab) {
      Text("Tab 1 contents")
        .tag(0)
        .tabItem {
          Image(nsImage: NSImage(named: NSImage.goLeftTemplateName)!)
          Text("Tab 1")
      }
      Text("Tab 2 contents")
        .tag(1)
        .tabItem {
          Image(nsImage: NSImage(named: NSImage.goRightTemplateName)!)
          Text("Tab 2")
      }
    }
  }
}

I can't seem to get the SwiftUI TabView images to work on macOS


What do you get exactly ?

What did you expect ?


Did you tryto replace:

          Image(nsImage: NSImage(named: NSImage.goLeftTemplateName)!)

with

          Image(systemName: "NSImage.goLeftTemplateName)


PS: I cannot test now, so not sure it even compiles.

Sorry, the issue is the icons will not show up, no matter the order of the Image/Text, or format of the Image() in the .tabItem{}. I've tried using .PNG files of size 32x32px, per the macOS Human Interface Guidelines (https://developer.apple.com/design/human-interface-guidelines/macos/icons-and-images/custom-icons/).


I'm looking to create a TabView with the "Freestanding Toolbar Icons" like you would get using NSTabViewController.TabStyle.toolbar


Is this a known limitation or a SwiftUI bug? If it's a limitation, and a "text segmented control style" is the only possibility on macOS, I think .tabItem{} should only accept Text on that platform.

I've run into this as well. I can't find anything like a .tabStyle modifier either. I've submitted a feature request. FB7660732

TabView images on macOS
 
 
Q