swiftui - Outlined symbol icons in tabs - Stack Overflow

I'm trying to create a tab vien in Swift UI.var body: some View {TabView {HomeView().tabItem {Ima

I'm trying to create a tab vien in Swift UI.

var body: some View {
    TabView {
        HomeView()
            .tabItem {
                Image(systemName: "house")
                Text("Home")
            }
        
        LibraryView()
            .tabItem {
                Image(systemName: "tv")
                Text("Library")
            }
        
        MyStuffView()
            .tabItem {
                Image(systemName: "bookmark")
                Text("My Stuff")
            }
    }
}

The problem is that even though I'm using outlined icons, the tab bar appears with filled icons, even when they are not selected. How do I get the bar to show the icons in their normal appearance? I had originally used Labels instead of Image + Text, but the result was the same.

I'm trying to create a tab vien in Swift UI.

var body: some View {
    TabView {
        HomeView()
            .tabItem {
                Image(systemName: "house")
                Text("Home")
            }
        
        LibraryView()
            .tabItem {
                Image(systemName: "tv")
                Text("Library")
            }
        
        MyStuffView()
            .tabItem {
                Image(systemName: "bookmark")
                Text("My Stuff")
            }
    }
}

The problem is that even though I'm using outlined icons, the tab bar appears with filled icons, even when they are not selected. How do I get the bar to show the icons in their normal appearance? I had originally used Labels instead of Image + Text, but the result was the same.

Share Improve this question edited Mar 2 at 16:54 jonrsharpe 122k30 gold badges268 silver badges476 bronze badges asked Mar 2 at 16:05 cesarcarloscesarcarlos 1,4491 gold badge15 silver badges42 bronze badges 1
  • Please show what your code produces, and what the "normal appearance" should be. – Sweeper Commented Mar 2 at 16:08
Add a comment  | 

1 Answer 1

Reset to default 1

This is probably intended by Apple to be a feature, to ensure consistent appearance between apps.

You might expect that the filled version can be turned off by applying the modifier .symbolVariant(.none), but this doesn't work. However, the documentation to this modifier explains how to ignore all symbol variants:

To cause a symbol to ignore the variants currently in the environment, directly set the symbolVariants environment value to none using the environment(_:_:) modifer.

This needs to be done for each image separately:

TabView {
    HomeView()
        .tabItem {
            Image(systemName: "house")
                .environment(\.symbolVariants, .none) // 

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745118630a4612282.html

相关推荐

  • swiftui - Outlined symbol icons in tabs - Stack Overflow

    I'm trying to create a tab vien in Swift UI.var body: some View {TabView {HomeView().tabItem {Ima

    8小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信