SwiftUI 中加载bundle中的图片

import SwiftUI

struct ContentView: View {
    
    var body: some View {
        Group{
            if let resBundlePath = Bundle.main.path(forResource: "Resources", ofType: "bundle"),
               let resBundle = Bundle(path: resBundlePath),
               let uiImage = UIImage(named: "imagename", in: resBundle, with: nil){
                    Image(uiImage: uiImage)
                        .resizable()
                        .scaledToFit()
            }else{
                Color.red
            }
        }
    }
}



struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
原文地址:https://www.cnblogs.com/chaostudy/p/15033303.html