Any Fresher Ways to Access Images in Asset Catalog

2019-05-23 06:02发布

I'm using an asset catalog with Xcode 5.1 and making an app for iOS 7 and above. The idea behind an asset catalog is that you can call the images whatever you want and the catalog associates the image with the correct device and orientation. In the background, Xcode apparently renames the files along the scheme mentioned here. However, it appears that there is a steady supply of problems accessing the files programmatically (here, here or especially here) without running into memory problems (e.g. here).

So I have the assets in my catalog and the launch images are called correctly. But I also want to use the launch images as background images, so I need to call those programmatically. In principle all that I should need to do, if I understand the asset catalog concept correctly, is something along these lines:

- (void) selectBackgroundImage {
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"LaunchImage"]];
}

And the OS should pick the correct launch image from the xcassets launch image set. However, this apparently only works if one uses the conventional names for the images, e.g. Default-Portrait@2x~iPad.png which defeats one claimed advantage of the asset catalog (any name you like) and may run into the aforementioned memory problems.

At this point, a few months after the referenced posts, are there better solutions? I know I can get rid of the asset catalog and access the files directly, or add a lot of work around code, or use the catalog along with the official file names, but none of these 'solutions' are in the spirit of what the asset catalog is supposed to do.

0条回答
登录 后发表回答