我有一个包含assets文件夹的包.我已经阅读了有关使用的堆栈的所有答案UIImage(named: "drop_arrow", inBundle: bundle, compatibleWithTraitCollection: nil)(好吧,它快速3等效)
path = Bundle.main.path(forResource: "LiveUI", ofType: "bundle")
if path != nil { // path with bundle is found
let bundle: Bundle = Bundle.init(path: path!)! // bundle is there
let image: UIImage? = UIImage(named: "HomePlayButton", in: bundle, compatibleWith: nil)
// HomePlayButton exists in the bundle/asset folder
// but image is nil
}
Run Code Online (Sandbox Code Playgroud)
这是我的项目结构:
你能看到项目代码/结构有什么问题吗?
要检查两件事.
1)确保您的资产包中包含一个Info.plist,其中包含一个包标识符.从截图中看,情况并非如此.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>MyBundle</string>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)
2)确保您的包中包含已编译的资产目录.应该命名为Assets.car.我不认为Xcode会在资源包内编译一个Assets.xcassets文件夹(该包对Xcode实际上是不透明的;同样它也不会编译你放在那里的任何.m源文件).在将资产包复制到应用程序包之前,您可能需要自定义构建步骤将已编译的Assets.car文件复制到资产包中.
您可以通过找到您的应用程序包并右键单击它然后"显示包内容",然后再次在包含的包上检查这些.
| 归档时间: |
|
| 查看次数: |
7017 次 |
| 最近记录: |