切分图片
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextTranslateCTM(context, 0, rect.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
int firstCol = floorf(CGRectGetMinX(rect) / tileSize);
int lastCol = floorf((CGRectGetMaxX(rect)-1) / tileSize);
int firstRow = floorf(CGRectGetMinY(rect) / tileSize);
int lastRow = floorf((CGRectGetMaxY(rect)-1) / tileSize);
for( int row = firstRow; row <= lastRow; row++ )
{
for( int col = firstCol; col <= lastCol; col++ )
{
UIImage = [self getTileWithRow:row column:col];
CGRect tileRect = CGRectMake((col * tileSize),
row * tileSize),
tileSize, tileSize);
CGContextDrawImage(context, tileRect, tile.CGImage);
}
}
CGContextRestoreGState(context);
}