在iPhone中添加图片、字符串文件到静态库

时间:2022-09-06 21:08:06

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.

我想创建一个静态库,它主要显示一些视图和按钮。我的客户希望将它作为库分发给其他iPhone开发人员使用。

My doubts are

我的疑问是

  • Can we add images and other resources to the library .a file?
  • 我们可以向库中添加图像和其他资源吗?
  • How can we include localization to this static library?(localizable.strings??)
  • 如何将本地化包含到这个静态库中?

4 个解决方案

#1


1  

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.)

库加上图像和资源正是框架的用途,而不是静态库。(免责声明:我是Mac程序员,不是iPhone程序员,所以就我所知,也许框架在iPhone上不太常见。)

#2


4  

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.

要使静态库本地化,请添加本地化。您为项目创建的字符串文件,包括库和所有工作正常。

#3


2  

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

由于iOS不允许使用框架,所以您有两个可能的选择:

  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.

    在静态库旁边打包一个“Resources”文件夹。它包含您的图像等。向库的用户提供关于资源应该放在哪里的文档(可能是复制到应用程序的资源文件夹中)。本地化文件将被导入到项目中。

  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..

    Base64(或其他任何)编码图像等,并将这些静态数据编译为库代码。这有点尴尬,但这是可以做到的。在加载显示(NSData等)时,必须对它们进行反编码。您可以提供一个资源类,用于存储已编码的对象并以未编码的形式返回它们。这里一个明显的缺点是您的代码可能会变得非常大——确保您只在实际需要时加载资源,并在完成时卸载资源。

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

但是,我不相信您可以嵌入(用于以后的使用)本地化字符串文件。

#4


0  

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

您可以将图像转换为二进制数据,并将它们作为char[]添加到库中。当需要图像时,就使用它

[[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

这个简单的应用程序将帮助您转换图像https://github.com/romann2/image-to - bin-data

#1


1  

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.)

库加上图像和资源正是框架的用途,而不是静态库。(免责声明:我是Mac程序员,不是iPhone程序员,所以就我所知,也许框架在iPhone上不太常见。)

#2


4  

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.

要使静态库本地化,请添加本地化。您为项目创建的字符串文件,包括库和所有工作正常。

#3


2  

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

由于iOS不允许使用框架,所以您有两个可能的选择:

  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.

    在静态库旁边打包一个“Resources”文件夹。它包含您的图像等。向库的用户提供关于资源应该放在哪里的文档(可能是复制到应用程序的资源文件夹中)。本地化文件将被导入到项目中。

  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..

    Base64(或其他任何)编码图像等,并将这些静态数据编译为库代码。这有点尴尬,但这是可以做到的。在加载显示(NSData等)时,必须对它们进行反编码。您可以提供一个资源类,用于存储已编码的对象并以未编码的形式返回它们。这里一个明显的缺点是您的代码可能会变得非常大——确保您只在实际需要时加载资源,并在完成时卸载资源。

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

但是,我不相信您可以嵌入(用于以后的使用)本地化字符串文件。

#4


0  

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

您可以将图像转换为二进制数据,并将它们作为char[]添加到库中。当需要图像时,就使用它

[[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

这个简单的应用程序将帮助您转换图像https://github.com/romann2/image-to - bin-data