Reputation: 63
In my iOS project, I creat a xcasset named:PaoPaoImages.xcassets then I put all images into PaoPaoImages.xcassets.
And I have a xib file named:a.xib, I compile it into a.nib. Then I put a.nib into a bundle named:paopao.bundle.
So, now, my images in PaoPaoImages.xcassets , and my nib in PaoPao.bundle. And the nib reference the images. Then, I run my project, the nib cannot show the images.
I'm stumped... any advice?
Upvotes: 0
Views: 502
Reputation:
In order to access the image from the Asset Catalog, you only need to access the name of the asset group without any extensions.
So, if you add an image named @"[email protected]" to the Asset Catalog, it will create an asset group called my-button.
Now, all you have to do is access the image like so:
In coding use following line
[UIImage imageNamed:@"my-button"];
instead of
[UIImage imageNamed:@"my-button.png"];
Also, you can edit the asset group by renaming it (without renaming the images) or changing it's individual components. This will allow you to follow easier naming conventions as well as show completely different assets between different UIScreen
scales without any scale checks.
In order to incorporate images for different device sizes, you may need to toggle it under the "Devices" subheading in the Asset Catalog Group's options.
Upvotes: 1
Reputation: 491
==> check here code try it:-
NSBundle *myImageBundle=[NSBundle bundleWithPath: myBundlePath];
NSArray *ImageURLs=[myImageBundleURLsForResourcesWithExtension:@"png" subdirectory:nil];
NSLog(@"imageURLS: %@",ImageURLs);
=>here refrence more try it:-
Access Asset Catalog programmatically
Load image from bundle with IOS
Upvotes: 0