美文网首页
pod加载图片

pod加载图片

作者: 轻云绿原 | 来源:发表于2019-06-20 11:26 被阅读0次

问题

你在pods里无法直接使用UIImage(name:String)加载本地的图片,

猜想:UIImage(name:String)会直接使用Bundle.main的路径,但Pods里的图片资源,不在Bundle.main路径里.

要找出图片资源在哪个Bundle里,再找出图片的路径,最后使用UIImage(contentsOfFile:String)找出图片

步骤

  1. 找出bundle
let myBundle = Bundle(for: PPFMultiImageViewController.self)
let myBundle = Bundle(for: self.classForCoder)
  1. 找出图片地址
let scale = Int(UIScreen.main.scale)
let path = myBundle.path(forResource: "backImage@\(scale)x", ofType: "png")!

3.UIImage

let image = UIImage(contentsOfFile: path)

相关文章

网友评论

      本文标题:pod加载图片

      本文链接:https://www.haomeiwen.com/subject/oirdqctx.html