Best way of loading images from application bundle

前端 未结 4 770
既然无缘
既然无缘 2021-02-07 09:20

What is the best way of loading images from the application main bundle. I am using

[UIImage imageNamed: \"image.png\"];

But I have heard that

4条回答
  •  没有蜡笔的小新
    2021-02-07 10:15

    For finding a single resource file using NSBundle

    NSBundle* myBundle = [NSBundle mainBundle];
    
    NSString* myImage = [myBundle pathForResource:@"Seagull" ofType:@"jpg"];
    

    and for finding multiple resources:

    NSBundle* myBundle = [NSBundle mainBundle];
    
    NSArray* myImages = [myBundle pathsForResourcesOfType:@"jpg"
                                  inDirectory:nil];
    

提交回复
热议问题