如何将 Tortuga 22 NinePatch 库包含到我的 XCode 项目中?

发布于 2024-09-03 18:32:40 字数 633 浏览 2 评论 0原文

首先,NinePatch 终于支持 iPhone,这要感谢 Tortuga 22 团队。不幸的是,对我来说,我无法将他们的库添加到我的项目中。

如果我只是将源文件拖放到我的项目中,我会收到大量“没有这样的文件或目录”-错误。如果我引用 libNinePatch.a 文件作为外部框架,我会得到相同的结果。

这样做的正确方法是什么?他们没有给出任何指示,所以我想必须有一种相当直接的方法来做到这一点。

提前致谢。
//Abeansits

First of all, there is finally NinePatch support for the iPhone, BIG thanks to the Tortuga 22 team for that. Unfortunately for me I have not been able to add their library to my project.

If I just drag and drop the source-files into my project I get a ton of "No such file or directory"-errors. If I reference the libNinePatch.a-file as an external framework I get the same result.

What is the proper way of doing this? There are no instructions from their part so I guess there must a fairly straight forward way of doing this.

Thanks in advance.
//Abeansits

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

残疾 2024-09-10 18:32:40

我只是想告诉每个仍在为此苦苦挣扎的人,我已将 podspec 上传到 CocoaPod 的存储库。

这意味着如果您的项目使用 CocoaPods(为什么不呢?),您只需添加:


吊舱“Tortuga22-NinePatch”

到您的 Podfile,您将获得 NinePatch 支持。 (请注意,它仍然不兼容 ARC,欢迎提出拉取请求!)

I just like to tell everyone still struggling with this that I've uploaded a podspec to CocoaPod's repository.

This means that if your project uses CocoaPods (and why wouldn't it?), you can just add:


pod 'Tortuga22-NinePatch'

To your Podfile and you'll have NinePatch support. (notice it's still not ARC-compatible, pull requests are welcome!)

合约呢 2024-09-10 18:32:40

我知道这是一个老问题,但只是为了帮助那些在 Objective C 中搜索 ninePatch 的人,我想告诉大家,从 ios 5 开始的 UIImage 类有一个方法可以做 ninePatch 所做的事情。

来自 UIImage参考

讨论

您可以使用此方法将大写插图添加到图像或
更改图像的现有上限插图。在这两种情况下,你都会得到
返回一个新图像,原始图像保持不变。

在缩放或调整图像大小期间,被盖子覆盖的区域
未缩放或调整大小。相反,未被盖子覆盖的像素区域
在每个方向上从左到右、从上到下平铺,以调整大小
图像。该技术通常用于创建可变宽度
按钮,保留相同的圆角,但其中心区域
根据需要增长或缩小。为了获得最佳性能,请使用平铺区域
这是一个大小为 1x1 像素的区域。

可用性 适用于 iOS 5.0 及更高版本。

在 UIImage.h 中声明

如果您想要带有固定顶部的图像,则使用示例:

UIImage* image = [UIImage imageNamed:@"YourImage.png"];
image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(25., 0, 0, 0)]

希望它有所帮助。

I know this is an old question, but just to help people that are searching for ninePatch in objective c, I want to inform that the UIImage class from ios 5 on, have a method to do what ninePatch do.

From UIImage reference:

Discussion

You use this method to add cap insets to an image or to
change the existing cap insets of an image. In both cases, you get
back a new image and the original image remains untouched.

During scaling or resizing of the image, areas covered by a cap are
not scaled or resized. Instead, the pixel area not covered by the cap
in each direction is tiled, left-to-right and top-to-bottom, to resize
the image. This technique is often used to create variable-width
buttons, which retain the same rounded corners but whose center region
grows or shrinks as needed. For best performance, use a tiled area
that is a 1x1 pixel area in size.

Availability Available in iOS 5.0 and later.

Declared In UIImage.h

An example of use if you want a image with a fix top:

UIImage* image = [UIImage imageNamed:@"YourImage.png"];
image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(25., 0, 0, 0)]

Hope it help.

夜吻♂芭芘 2024-09-10 18:32:40

您应该能够将文件添加到您的项目中。 这个问题的答案可能会有所帮助。

另外,请注意 UIImage 确实提供可拉伸图像。请参阅 -stretchableImageWithLeftCapWidth:topCapHeight: 了解详细信息。如果您需要读取实际的九个补丁格式的图像,这对您没有帮助,也许是为了与 Android 应用程序共享资源,但这通常是真正需要的。

You should be able to add the files to your project. Answers to this SO question may help.

Also, be aware that UIImage does provide stretchable images. See -stretchableImageWithLeftCapWidth:topCapHeight: for details. That won't help you if you need to read images in actual nine patch format, perhaps for sharing resources with an Android app, but it's often all that's really needed.

热鲨 2024-09-10 18:32:40

您是否在需要的类或 prefix.pch 文件中 #include-ing 主头文件?

Are you #include-ing the main header file(s) in whichever classes you need them or in the prefix.pch file?

能否归途做我良人 2024-09-10 18:32:40

如果您从 GitHub 下载他们的源代码包,您会看到他们已经包括一个示例项目 NinePatchDemo。检查它应该会为您提供所需的所有信息。

您会看到他们刚刚将 NinePatch Xcode 项目放入“Other Sources”下的 NinePatchDemo 项目中。您可以用同样的方式将 NinePatch 项目拖放到您自己的项目中。您可以检查构建和目标设置,以确保包含构建所需的任何路径/库。

看起来您希望在目标的其他链接器标志中使用 -all_load -ObjC ,并且如果您的项目文件夹与 ninepatch 文件夹位于同一级别(如从 github 下载的那样),您将还想将目标上的标题搜索路径设置为 ../NinePatch//**,如果您移动了任何文件夹,则相应地进行更改。

除此之外,我唯一能看到的是,您当然需要包含

为我构建良好的 #import NinePatchDemo 的标头,因此我可以验证它们的源确实有效。

If you download their source package from GitHub, you'll see that they've included an example project, NinePatchDemo. Inspecting this should give you all the information you need.

You'll see that they just dropped the NinePatch Xcode Project into the NinePatchDemo project, under "Other Sources". You can drag and drop the NinePatch project into your own in the same way. You can check the build and target settings to make sure you're including any paths/libraries that you need in order to build.

It looks like you want -all_load -ObjC in Other Linker flags for your target, and if your project folder is at the same level as the ninepatch folder (as in the download from github), you'll also want to set the Header Search Paths on your target to ../NinePatch//**, varying accordingly if you've moved any folders around.

Other than that the only thing I can see is that you will, of course, need to include the headers with #import <TUNinePatch.h>

NinePatchDemo built fine for me, so I can verify that their source does work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文