I didn't want to load so much code for the simple 9 patch images we had. So anyway, here's a simple solution to the problem for those interested. It's somewhat hard coded to our 3 pixel stretch regions but you could easily adjust those to your needs or find those in the image with some basic code and use that instead of my hard-coded inset parameters.
+ (UIImage *) makeNinePatchImage:(UIImage *)image;
{
//Clear the black 9patch regions
CGRect imageRect = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
UIGraphicsBeginImageContextWithOptions(image.size, NO, [UIScreen mainScreen].scale);
[image drawInRect:imageRect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClearRect(context, CGRectMake(0, 0, image.size.width, 1));
CGContextClearRect(context, CGRectMake(0, 0, 1, image.size.height));
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIEdgeInsets insets;
//hard coded for now, could easily read the black regions if necessary
insets.left = insets.right = image.size.width / 2 - 1;
insets.top = insets.bottom = image.size.height / 2 - 1;
UIImage *nineImage = [image resizableImageWithCapInsets:insets
resizingMode:UIImageResizingModeStretch];
return nineImage;
}
Then to use it in say, a button's background, just call it like this:
[self.dummyButton setBackgroundImage:[EVUtility makeNinePatchImage:learnMoreImage] forState:UIControlStateNormal];
Done.