V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
ShuS
V2EX  ›  iOS

[iOS 开发疑问] [自建 framework] framework 下访问图片资源的问题

  •  
  •   ShuS · Oct 14, 2015 · 2971 views
    This topic created in 3856 days ago, the information mentioned may be changed or developed.

    我现在是想要自建一个 framework 。然后我先是创建了一个普通 app 应用工程,在该应用工程中添加了一个 framework 的 target 。一般都是采用这种方式来开发并调试自己的 framework 的。

    现在碰到的一个问题是,我在该 framework 中要访问一个图片资源,假设名为 image 。
    我尝试了三种方法访问该图片均失败。
    UIImage *image = [UIImage imageNamed:@"image"];
    if(!image){
    image = [UIImage imageNamed:@"FRAMEWORK/image"];
    if (!image) {
    image = [UIImage imageNamed:@"FRAMEWORK.framework/image"];
    }
    }
    请问有大神能够帮忙解决问题吗?

    MerenguesGeek
        1
    MerenguesGeek  
       Oct 14, 2015
    是不能用 imageNamed:这个方法去读取的,何不试试 imageWithContentsOfFile:呢?
    ShuS
        2
    ShuS  
    OP
       Oct 14, 2015
    @MerenguesGeek 不行啊,或者推荐一下使用方法?
    我是这样
    NSString *path = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"];

    UIImage *image = [UIImage imageWithContentsOfFile:path];
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   780 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 19:40 · PVG 03:40 · LAX 12:40 · JFK 15:40
    ♥ Do have faith in what you're doing.