我正在努力将一张图片加载到Image控件中。我正在开发一个MacOS应用程序,与iOS略有不同。
我已经在互联网上搜索了一些资料,但是只找到了几篇关于iOS如何实现的回答。
请检查以下代码:
import SwiftUI
struct ContentView: View {
let myUrl = URL(fileURLWithPath: "/Users/codegrinder/Documents/turtlerock.jpg")
init() {
//TODO Do something with the myUrl which is valid (not nil)
}
var body: some View {
Image("turtlerock")
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment:.center)
//I need to put the param to Image what I want to load an image from myUrl
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}