如何将 Tortuga 22 NinePatch 库包含到我的 XCode 项目中?
首先,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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我只是想告诉每个仍在为此苦苦挣扎的人,我已将 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!)
我知道这是一个老问题,但只是为了帮助那些在 Objective C 中搜索 ninePatch 的人,我想告诉大家,从 ios 5 开始的 UIImage 类有一个方法可以做 ninePatch 所做的事情。
来自 UIImage参考:
如果您想要带有固定顶部的图像,则使用示例:
希望它有所帮助。
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:
An example of use if you want a image with a fix top:
Hope it help.
您应该能够将文件添加到您的项目中。 这个问题的答案可能会有所帮助。
另外,请注意 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.
您是否在需要的类或 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?
如果您从 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.