//
// UIImageAdditions.m
// Newspress
//
// Created by Kyle Van Essen on 10-04-10.
// Copyright 2010 Vibealicious. All rights reserved.
//
#import "UIImageAdditions.h"
@implementation UIImage (Additions)
+(void)drawNinePartImage:(NSArray *)images inRect:(CGRect)rect
{
CGPoint origin = rect.origin;
CGSize size = rect.size;
NSInteger partCount = 9;
if ([images count] < partCount)
return;
CGRect rects[partCount];
UIImage *image;
// Top Row
image = [images objectAtIndex:0];
rects[0] = CGRectMake(origin.x, origin.y, image.size.width, image.size.height);
image = [images objectAtIndex:2];
rects[2] = CGRectMake(origin.x + size.width - image.size.width, origin.y, image.size.width, image.size.height);
image = [images objectAtIndex:1];
rects[1] = CGRectMake(rects[0].size.width + rects[0].origin.x, origin.y, size.width - rects[0].size.width - rects[2].size.width, image.size.height);
// Bottom Row
image = [images objectAtIndex:6];
rects[6] = CGRectMake(origin.x, origin.y + size.height - image.size.height, image.size.width, image.size.height);
image = [images objectAtIndex:8];
rects[8] = CGRectMake(origin.x + size.width - image.size.width, origin.y + size.height - image.size.height, image.size.width, image.size.height);
image = [images objectAtIndex:7];
rects[7] = CGRectMake(rects[6].size.width + rects[6].origin.x, origin.y + size.height - image.size.height, size.width - rects[6].size.width - rects[8].size.width, image.size.height);
// Middle Row
image = [images objectAtIndex:3];
rects[3] = CGRectMake(origin.x, origin.y + rects[0].size.height, image.size.width, size.height - rects[0].size.height - rects[6].size.height);
image = [images objectAtIndex:5];
rects[5] = CGRectMake(origin.x + size.width - image.size.width, origin.y + rects[0].size.height, image.size.width, size.height - rects[2].size.height - rects[8].size.height);
image = [images objectAtIndex:4];
rects[4] = CGRectMake(rects[3].size.width + rects[3].origin.x, origin.y + rects[0].size.height, size.width - rects[0].size.width - rects[2].size.width, size.height - rects[1].size.height - rects[7].size.height);
for (NSInteger index = 0; index < partCount; index++)
{
UIColor *pattern = [[UIColor alloc] initWithPatternImage:[images objectAtIndex:index]];
//NSLog(@"Frame: %f, %f, %f, %f", rects[index].origin.x, rects[index].origin.y, rects[index].size.width, rects[index].size.height);
[pattern set];
CGContextSetPatternPhase(UIGraphicsGetCurrentContext(), CGSizeMake(rects[index].origin.x, rects[index].origin.y));
UIRectFill(rects[index]);
[pattern release];
}
[[UIColor clearColor] set];
}
@end
// UIImageAdditions.m
// Newspress
//
// Created by Kyle Van Essen on 10-04-10.
// Copyright 2010 Vibealicious. All rights reserved.
//
#import "UIImageAdditions.h"
@implementation UIImage (Additions)
+(void)drawNinePartImage:(NSArray *)images inRect:(CGRect)rect
{
CGPoint origin = rect.origin;
CGSize size = rect.size;
NSInteger partCount = 9;
if ([images count] < partCount)
return;
CGRect rects[partCount];
UIImage *image;
// Top Row
image = [images objectAtIndex:0];
rects[0] = CGRectMake(origin.x, origin.y, image.size.width, image.size.height);
image = [images objectAtIndex:2];
rects[2] = CGRectMake(origin.x + size.width - image.size.width, origin.y, image.size.width, image.size.height);
image = [images objectAtIndex:1];
rects[1] = CGRectMake(rects[0].size.width + rects[0].origin.x, origin.y, size.width - rects[0].size.width - rects[2].size.width, image.size.height);
// Bottom Row
image = [images objectAtIndex:6];
rects[6] = CGRectMake(origin.x, origin.y + size.height - image.size.height, image.size.width, image.size.height);
image = [images objectAtIndex:8];
rects[8] = CGRectMake(origin.x + size.width - image.size.width, origin.y + size.height - image.size.height, image.size.width, image.size.height);
image = [images objectAtIndex:7];
rects[7] = CGRectMake(rects[6].size.width + rects[6].origin.x, origin.y + size.height - image.size.height, size.width - rects[6].size.width - rects[8].size.width, image.size.height);
// Middle Row
image = [images objectAtIndex:3];
rects[3] = CGRectMake(origin.x, origin.y + rects[0].size.height, image.size.width, size.height - rects[0].size.height - rects[6].size.height);
image = [images objectAtIndex:5];
rects[5] = CGRectMake(origin.x + size.width - image.size.width, origin.y + rects[0].size.height, image.size.width, size.height - rects[2].size.height - rects[8].size.height);
image = [images objectAtIndex:4];
rects[4] = CGRectMake(rects[3].size.width + rects[3].origin.x, origin.y + rects[0].size.height, size.width - rects[0].size.width - rects[2].size.width, size.height - rects[1].size.height - rects[7].size.height);
for (NSInteger index = 0; index < partCount; index++)
{
UIColor *pattern = [[UIColor alloc] initWithPatternImage:[images objectAtIndex:index]];
//NSLog(@"Frame: %f, %f, %f, %f", rects[index].origin.x, rects[index].origin.y, rects[index].size.width, rects[index].size.height);
[pattern set];
CGContextSetPatternPhase(UIGraphicsGetCurrentContext(), CGSizeMake(rects[index].origin.x, rects[index].origin.y));
UIRectFill(rects[index]);
[pattern release];
}
[[UIColor clearColor] set];
}
@end