Re: Loading image resources
Re: Loading image resources
- Subject: Re: Loading image resources
- From: Quincey Morris <email@hidden>
- Date: Sun, 14 Sep 2014 19:03:02 +0000
On Sep 14, 2014, at 11:37 , Charles Jenkins <email@hidden> wrote:
> Okay, here’s a point on which I may need education. Xcode created my project with an images.xcassets folder right there in it, and that’s where I’m adding my images. Do you mean that’s not enough? I need to add images.xcassets to the target somewhere else? How do I do that?
Well, it depends … :)
If you’re talking about image sets (that is, images that have multiple resolution representations), then you create the image set within the images.xcassets editor in Xcode. In this case, the original image files are just used to populate the image set, and then aren’t used again. (Xcode copies the image data at the various resolutions into a bundle inside images.xcassets.) All you need to do is ensure that the images.xcassets item is itself marked as being part of the target(s) in which it’s used. To do this, you can check the target membership checkbox in the utility inspector at the right of the window.
[Aside: In this case, you don’t want or need to add your original image files to the project navigator. However, if you want those files to be under source control, I guess you would add them anyway, but just leave them out of any targets.]
If you’re talking about plain ol' image files, then you have to add them to the project navigator, and then check their target membership checkboxes. In this case, assuming you’re using PNG, you’ll likely have multiple files per image, in 1x, 2x and 3x resolutions, and your code will manage these in the old-fashioned way.
I’ve never tried to put such “loose” image files into the images.xcassets folder, and I don’t even know if it’s supported. Possibly the contents of images.xcassets is intended to be private to Xcode. However, I do have a project someone else gave me, and there are loose image files in there, and it seems to work OK.
All these layers of complexity are historical, unfortunately, so it doesn’t necessarily make a lot of sense now. As I tried inadequately to say earlier, you need to start by examining a built copy of your app. Find out what files are there, what they’re called, and what directory they’re in. If the files are missing or misplaced, then you need to fix that in the Xcode project. Then, if your code is making wrong assumptions (such as expecting the files to have an extension that they don’t really have), you’ll finally get to fix your code.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden