How to change filled icon to not filled on TabView tabItem in iOS 15 Xcode 13?
Asked Answered
A

1

6

How can i change filled icon to not filled on TabView tabItem in iOS 15 Xcode 13?

It seems now that the icons are filled by default...

My code :

import SwiftUI

struct Test_Home_V: View {
    var body: some View {
        TabView {
            HomeList_V()
                .tabItem {
                    Label("_HomeTitle", systemImage: "house")
                }
...

Note : From iOS 15 you should not explicitly request the filled variant of SF Symbols icons, because the system will automatically use them as appropriate.

So how can I get my icons (SF Symbols) in outline like before?

Thanks

Akihito answered 24/9, 2021 at 18:19 Comment(0)
E
19

To solve this, we can use environment(\.symbolVariants, .none).

https://developer.apple.com/documentation/swiftui/symbolvariants/none

Using this variant with the symbolVariant(:) modifier doesn’t have any effect. Instead, to show a symbol that ignores the current variant, directly set the symbolVariants environment value to none using the environment(:_:) modifer:

import SwiftUI

struct ContentView: View {
    var body: some View {
        TabView {
            Text("content")
                .tabItem {
                    Label("tab", systemImage: "creditcard")
                }
            
            Text("content")
                .tabItem {
                    Label("tab", systemImage: "creditcard")
                        .environment(\.symbolVariants, .none) // here
                }
        }
    }
}

The result:

Result

Exoskeleton answered 2/10, 2021 at 6:19 Comment(1)
This is exactly what i want! Thank you Konomae!Akihito

© 2022 - 2024 — McMap. All rights reserved.