Different symbols for different iOS-Versions.

Hi there,

I am currently developing an app with a tab view. Unfortunately some the symbols I use only work for iOS 17. I would like to change a symbol but only for iOS 16. Is this possible? Thank you for your help!

Laurin

Here is my code:


struct ContentView: View {
    var body: some View {
        TabView {
            Group {
                Medikamente()
                    .tabItem {
                        Image(systemName: "syringe")
                        Text("Medikamente")
                    }
                BPR()
                    .tabItem {
                        Image(systemName: "point.bottomleft.forward.to.arrowtriangle.uturn.scurvepath")
                        Text("BPR")
                    }
                InvasiveMassnahmen()
                    .tabItem {
                        Image(systemName: "heart.text.square")
                        Text("Maßnahmen")
                    }
            }
        }
    }
}
        
        #Preview {
            ContentView()
        }

Answered by darkpaw in 770216022

Here's one way of doing it:

struct ContentView: View {
	var body: some View {

		if #available(iOS 17, *) {
      //  If iOS 17 or greater is in use, these symbols will be used
			let kSymbolMedikamente: String = "syringe"
			let kSymbolBPR: String = "point.bottomleft.forward.to.arrowtriangle.uturn.scurvepath"
			let kSymbolInvasiveMassnahmen: String = "heart.text.square"
		} else {
			// Anything lower than iOS 17 will use these symbols
			let kSymbolMedikamente: String = "syringe"
			let kSymbolBPR: String = "point.bottomleft.forward.to.arrowtriangle.uturn.scurvepath"
			let kSymbolInvasiveMassnahmen: String = "heart.text.square"
		}

		TabView {
			Group {
				Medikamente()
					.tabItem {
						Image(systemName: kSymbolMedikamente)
						Text("Medikamente")
					}
				BPR()
					.tabItem {
						Image(systemName: kSymbolBPR)
						Text("BPR")
					}
				InvasiveMassnahmen()
					.tabItem {
						Image(systemName: kSymbolInvasiveMassnahmen)
						Text("Maßnahmen")
					}
			}
		}
	}
}
Accepted Answer

Here's one way of doing it:

struct ContentView: View {
	var body: some View {

		if #available(iOS 17, *) {
      //  If iOS 17 or greater is in use, these symbols will be used
			let kSymbolMedikamente: String = "syringe"
			let kSymbolBPR: String = "point.bottomleft.forward.to.arrowtriangle.uturn.scurvepath"
			let kSymbolInvasiveMassnahmen: String = "heart.text.square"
		} else {
			// Anything lower than iOS 17 will use these symbols
			let kSymbolMedikamente: String = "syringe"
			let kSymbolBPR: String = "point.bottomleft.forward.to.arrowtriangle.uturn.scurvepath"
			let kSymbolInvasiveMassnahmen: String = "heart.text.square"
		}

		TabView {
			Group {
				Medikamente()
					.tabItem {
						Image(systemName: kSymbolMedikamente)
						Text("Medikamente")
					}
				BPR()
					.tabItem {
						Image(systemName: kSymbolBPR)
						Text("BPR")
					}
				InvasiveMassnahmen()
					.tabItem {
						Image(systemName: kSymbolInvasiveMassnahmen)
						Text("Maßnahmen")
					}
			}
		}
	}
}
Different symbols for different iOS-Versions.
 
 
Q