Adding images, a string file to a static library in iPhone

I want to create a static library that basically displays some views and a button. My client wants this to be distributed as a library to be used by other iPhone developers.

My doubts:

  • Can we add images and other resources to the .a file library?
  • How to enable localization in this static library? (localizable.strings ??)
+3
source share
4 answers

A library plus images and resources is exactly what the infrastructure is for, not a static library. (Disclaimer: I'm a Mac programmer, not an iPhone programmer, so as far as I know, iPhone frameworks are less common.)

+1
source

That's right, you cannot include localization files in your static library. This is just one of many shortcomings that you have to deal with when developing a static library.

To make your static library localized, add the Localizable.strings files that you created in your project, including your library, and everything works fine.

+4
source

Since Framework is not allowed on iOS, you have 2 possible options:

  • Build the Resources folder along with the static library. It contains your images, etc. Provide documentation to the library user about where the resources should go (presumably copied to the Application Resources folder). Localization files will be imported into the project.

  • Base64 (or something else) encodes images, etc. and compiles them as static data into library code. This is a little inconvenient, but it can be done. You must encode them at boot to display (NSData, etc.). You can provide a resource class that stores encoded objects and returns them in its unencrypted form. One of the obvious drawbacks here is that your code can become quite large - make sure that you only load resources when it is really needed, and unload them after completion.

I do not believe that you can embed (for later use) localization string files.

+2
source

You can convert images to binary data and add them to the library as char []. Then when the image is needed just use

[[UIImage alloc] initWithData:[NSData dataWithBytesNoCopy:(void*)<CHAR_ARRAY_NAME> length:sizeof(<CHAR_ARRAY_NAME>) freeWhenDone:NO]]; 

This simple application will help you convert images https://github.com/RomanN2/image-to-binary-data

0
source

All Articles