代码之家  ›  专栏  ›  技术社区  ›  Scaraux

cocoapods无法从bundle加载图像

  •  -1
  • Scaraux  · 技术社区  · 7 年前

    我知道这是一个经常出现的问题,但我发现所有的帖子都过时了…

    我只是想把我的Cocoapods项目中的一个图像加载到一个图像中。总是这样 nil

    我把图片close.png复制到里面 MyPodProject/Assets

    s.resource_bundle = { 'MyPodProject' => 'MyPodProject/Assets/*.png' }
    
    let view = UIImageView(frame: self.bounds)
    let bundle = Bundle(for: Test.self)
    let image = UIImage(named: "close", in: bundle, compatibleWith: nil)
    

    关闭图像出现在xcode中的generated resources文件夹中…. 我试了三个小时…

    1 回复  |  直到 7 年前
        1
  •  0
  •   Scaraux    7 年前
     s.resources = 'Hashtags/Assets/**/*.{png,storyboard}'
     s.resource_bundle = { 'Hashtags' => 'Hashtags/Assets/*.png' }
    

    let view = UIImageView(frame: self.bounds)
    let bundle = Bundle(for: Test.self)
    let image = UIImage(named: "close", in: bundle, compatibleWith: nil)