关于 ios:从私有 pod 的资产目录中加载图像 | 珊瑚贝

Loading images from asset catalog from private pod


我创建了一个包含一些图像的私有 pod,我已将这些图像放在资产目录中,现在当我尝试访问它时,它不会加载到我安装了这个私有 pod

的主机应用程序中

这是我的私人 podspec

1
2
3
s.resource_bundles = {
     ‘myPod’ => [‘myPod/Assets/*.xcassets’]
  }

我已经在使用 pod

创建的 Assets 文件夹中添加了这个资产目录

这在我的 VC 里面 viewDidLoad 在我的私人 pod

1
2
3
4
if let image = UIImage(named:”myIcon”, in:Bundle(for:myVC.self), compatibleWith: nil) {
    sendButton.setImage(image.withRenderingMode(.alwaysTemplate), for: .normal)
    sendButton.setTitle(“”, for: .normal)
}

我还可以在我的主机应用程序、资源文件夹内的 pods 部分中看到该资产文件,而且我的包也不是零。


最后,我找到了一个解决方案,原来问题出在资源包上,我可以看到 Assets.car 存在于包中,但图像仍未加载。

我认为使用 png 文件可能会起作用,我可以看到它被复制到包中,但我无法使用图像名称访问它,结果我必须将其添加到图像名称 myPod.bundle/imageName 并且它有效但这仍然不是一个好的解决方案。

最后有一个更干净更简单的解决方案,就是在 pod spec 文件中使用 resources 而不是 resource_bundles,就是这样。

1
s.resources = ‘myPod/Assets/**’

然后进行 pod install,它会从你的资产目录中加载图片。


来源:https://www.codenong.com/53680610/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_8714.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?