iOS framework之bundle资源获取

在framework内部获取framework里的bundle资源

    NSBundle *bundle = [NSBundle bundleWithPath:[[NSBundle bundleForClass:[self class]] pathForResource:@"myBundle" ofType:@"bundle"]];
    NSString *imagePath = [bundle pathForResource:@"icon@2x" ofType:@"png"];
    UIImage *image = [UIImage imageWithContentsOfFile:imagePath];

将framework添加到项目里,在项目里获取framework里的bundle资源

    NSString *frameworkPath = [[NSBundle mainBundle] pathForResource:@"Frameworks/MyFramework" ofType:@"framework"];

    //得到对应的bundle路径
    NSBundle *frameworkBundle =  [NSBundle bundleWithPath:frameworkPath];

    //得到资源的bundle路径
    NSBundle *vivienBundle = [NSBundle bundleWithPath:[frameworkBundle pathForResource:@"myBundle" ofType:@"bundle"]];
        
    NSString *pic1 = [vivienBundle pathForResource:@"icon@2x" ofType:@"png"];
        
    UIImage *image = [UIImage imageWithContentsOfFile:pic1];
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容