Skip to content

Commit

Permalink
more coherent resize methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sgtsquiggs committed Oct 11, 2013
1 parent 4da7fab commit 5567223
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Categories/UIImage+Resizing.h
Expand Up @@ -24,6 +24,13 @@ typedef enum
NYXCropModeCenter
} NYXCropMode;

typedef enum
{
NYXResizeModeScaleToFill,
NYXResizeModeAspectFit,
NYXResizeModeAspectFill
} NYXResizeMode;


@interface UIImage (NYX_Resizing)

Expand All @@ -34,6 +41,11 @@ typedef enum

-(UIImage*)scaleByFactor:(float)scaleFactor;

-(UIImage*)scaleToSize:(CGSize)newSize usingMode:(NYXResizeMode)resizeMode;

// NYXResizeModeScaleToFill resize mode used
-(UIImage*)scaleToSize:(CGSize)newSize;

// Same as 'scale to fill' in IB.
-(UIImage*)scaleToFillSize:(CGSize)newSize;

Expand Down
19 changes: 19 additions & 0 deletions Categories/UIImage+Resizing.m
Expand Up @@ -83,6 +83,25 @@ -(UIImage*)scaleByFactor:(float)scaleFactor
return [self scaleToFillSize:scaledSize];
}

-(UIImage*)scaleToSize:(CGSize)newSize usingMode:(NYXResizeMode)resizeMode
{
switch (resizeMode)
{
case NYXResizeModeAspectFit:
return [self scaleToFitSize:newSize];
case NYXResizeModeAspectFill:
return [self scaleToCoverSize:newSize];
default:
return [self scaleToFillSize:newSize];
}
}

/* Convenience method to scale the image using the NYXResizeModeScaleToFill mode */
-(UIImage*)scaleToSize:(CGSize)newSize
{
return [self scaleToFillSize:newSize];
}

-(UIImage*)scaleToFillSize:(CGSize)newSize
{
size_t destWidth = (size_t)(newSize.width * self.scale);
Expand Down

0 comments on commit 5567223

Please sign in to comment.