开发者

Add images, string file to static library in iPhone

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

My doubts are

  • Can we add images and other resourc开发者_开发知识库es to the library .a file?
  • How can we include localization to this static library?(localizable.strings??)


This is correct, you CAN't include localitation files to your static library. This only one of many disadvantages you have to deal with when developing a static library.

To make your static library localized, add the Localizable.strings files you have created to your project, that includes your library and all works fine.


Since Frameworks are not allowed on iOS, you have 2 likely choices:

  1. Package a "Resources" folder alongside the static library. This contains your images, etc. Provide documentation to the user of the library as to where the resources should go (presumably copied into the app's Resources folder). Localization files would be imported into the project.

  2. Base64 (or whatever) encode images, etc, and compile those as static data into the library code. This is a little awkward, but it can be done. You have to un-encode them when loading them for display (NSData etc). You could provide a resources class which stores the encoded objects and returns them in their un-encoded form. One obvious drawback here is that your code could get pretty large -- make sure you only load the resources when actually needed and unload when done..

I don't believe you can embed (for later use) localization string files however.


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


You can convert images into binary data and add them to the library as a 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 to convert images https://github.com/RomanN2/image-to-binary-data

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜