仅当iOS 14、SwiftUI
我想显示一个文本视图,例如:仅当iOS 14、SwiftUI,ios,swiftui,ios14,Ios,Swiftui,Ios14,我想显示一个文本视图,例如: Text("Welcome to iOS 14") 如果用户正在使用iOS 14 如果用户正在使用其他iOS版本,我希望显示不同的文本视图,请说: Text("Welcome to Different iOS version") 我怎样才能做到这一点呢?本文还介绍了14.1、14.2等版本 struct ContentView: View { var systemVersion = UIDevice.c
Text("Welcome to iOS 14")
如果用户正在使用iOS 14
如果用户正在使用其他iOS版本,我希望显示不同的文本视图,请说:
Text("Welcome to Different iOS version")
我怎样才能做到这一点呢?本文还介绍了14.1、14.2等版本
struct ContentView: View {
var systemVersion = UIDevice.current.systemVersion
var body: some View {
if systemVersion.starts(with: "14" ) {
Text("welcome to ios 14")
} else {
Text("Welcome to Different iOS version")
}
}
}
返回一个字符串,您可以添加任意数量的房屋。你可以把这个概念应用到任何事情上
struct ContentView: View {
public var systemVersion: String? {
return UIDevice.current.systemVersion // "14.2" in my case
}
var getMessageSystem: String {
guard let versionOS = Double(systemVersion!)
else { return "Not a valid iOS version" }
switch versionOS {
case _ where versionOS > 14: return "welcome to iOS 14"
case _ where versionOS > 13: return "welcome to iOS 13"
case _ where versionOS > 12: return "welcome to iOS 12"
default: return "welcome"
}
}
var body: some View {
Text(getMessageSystem) // welcome to iOS 14
}
}
你称之为文本视图的东西是什么<代码>文本编辑器?文本视图表示文本(“某些文本”)将开发目标设置为iOS 13.x,并将文本编辑器带到内容视图。Xcode会告诉你怎么做。我不认为这是他或她在说的。可能是,我会等一下。这对我有帮助,但不是我在说的。我不能向上投票给你,因为我没有足够的声誉,否则我会向上投票给你。你是否只想在iOS 14中显示一些视图,而不是在iOS 14中显示另一个视图?两种不同的视图表示我想根据用户的iOS版本显示的文本或图像。