ios 加載.bundle文件里的圖片


這個是加載bundle里面的的圖片

+ (UIImage *)imageNamed:(NSString *)name ofBundle:(NSString *)bundleName {

    UIImage *image = nil;

    NSString *image_name = [NSString stringWithFormat:@"%@.png", name];

    NSString *resourcePath = [[NSBundle mainBundle] resourcePath];

    NSString *bundlePath = [resourcePath stringByAppendingPathComponent:bundleName];

    NSString *image_path = [bundlePath stringByAppendingPathComponent:image_name];;

    image = [[UIImage alloc] initWithContentsOfFile:image_path];

    return image;

}

 

    // 加載自定義名稱為Resources.bundle中對應images文件夾中的圖片

    // 思路:從mainbundle中獲取resources.bundle

    NSString *strResourcesBundle = [[NSBundle mainBundle] pathForResource:@"Resources" ofType:@"bundle"];

    // 找到對應images夾下的圖片

    NSString *strC = [[NSBundle bundleWithPath:strResourcesBundle] pathForResource:@"C" ofType:@"png" inDirectory:@"images"];

    UIImage *imgC = [UIImage imageWithContentsOfFile:strC];

    [imageView setImage:imgC];

 

//在.bundle文件里面添加圖片

將圖片文件直接拖拽進來

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM