How to include images in a library in iOS / Xcode 4

I have an Xcode workspace with several projects, say Foo and Baz, which both depend on some common code, which happens to be the code of the RCSwitch toggle button (can be found here if anyone is interested). RCSwitch comes with several image files that you must download when you start Foo or Baz. They are loaded using the UIImage imageNamed message: so

UIImage *knobTmpImage = [[[UIImage imageNamed:@"btn_slider_thumb.png"] retain] autorelease]; 

I understand that in order to work, images must be part of the application package. My question is how to get them there from my library? I tried to add the โ€œCopy Bundle Resourcesโ€ build phase to my library project and then add all the images to this without any effect. Images are not detected at runtime.

Then I tried to add images to the "Copy Bundle Resources" build phase for Foo and Baz; you need to select "Add others" because the dialog box does not list resources outside the current project. It really works, but it seems like a weird way to do it. Neither Fo nor Baz should have knowledge of the internal library. What if I want to send the library to external clients?

Is there any other way to do this? Is it possible to have images or other resources in the libXXX.a file?

+6
source share
1 answer

What I do for this is that my static library creates a package that I include in the main application project. If you use the sub project / sibling project in the workspace, then this package can be added in such a way that if you edit the library project to add another image, it will be restored, which means that the main application project is receiving changes.

I wrote a tutorial about it here - http://www.galloway.me.uk/tutorials/ios-library-with-resources/

The bit that interests you is the category on UIImage that I use to get images in the library package. Therefore, from the library code, I use the method added to the category to capture the image from the right package.

+3
source

Source: https://habr.com/ru/post/893831/


All Articles