Question

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

Was it helpful?

Solution

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

OTHER TIPS

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.

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.

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top