Declared in UIImage+DTFoundation.h

Overview

Methods to help with working with images.

Class Methods

imageWithContentsOfURL:cachePolicy:error:

Creates and returns an image object synchronously by loading the image data from the specified URL and optionally caching it.

+ (UIImage *)imageWithContentsOfURL:(NSURL *)URL cachePolicy:(NSURLRequestCachePolicy)cachePolicy error:(NSError **)error

Parameters

URL

The URL to load the image from

cachePolicy

The cache policy to apply.

error

An optional output parameter to return an error if the loading fails

Return Value

The image object for the specified URL, or nil if the method could not load the specified image.

Discussion

Useful values for cachePolicy are:

  • NSURLRequestUseProtocolCachePolicy (default)
  • NSURLRequestReloadIgnoringLocalCacheData
  • NSURLRequestReturnCacheDataElseLoad
  • NSURLRequestReturnCacheDataDontLoad

Declared In

UIImage+DTFoundation.h

imageWithSolidColor:size:

Creates an image filled with a solid color

+ (UIImage *)imageWithSolidColor:(UIColor *)color size:(CGSize)size

Parameters

color

The solid color that fills the image

size

The size of the image

Return Value

The image filled with given color and given size

Declared In

UIImage+DTFoundation.h

Instance Methods

drawInRect:withContentMode:

Mimicks the way images are drawn differently by UIImageView based on the set content mode.

- (void)drawInRect:(CGRect)rect withContentMode:(UIViewContentMode)contentMode

Parameters

rect

The rectangle to drawn in

contentMode

The content mode. Note that UIViewContentModeRedraw is treated the same as UIViewContentModeScaleToFill.

Declared In

UIImage+DTFoundation.h

imageMaskedAndTintedWithColor:

Creates an image filled with a tint color using the receiver as image mask. The resulting image ignores the receiver’s color values and instead uses the alpha values combined with the passed color.

- (UIImage *)imageMaskedAndTintedWithColor:(UIColor *)color

Parameters

color

The color to use for tinting

Return Value

A new image

Declared In

UIImage+DTFoundation.h

imageScaledToSize:

Resizes the receiver to the given size.

- (UIImage *)imageScaledToSize:(CGSize)newSize

Parameters

newSize

The target image size

Return Value

The resulting image

Declared In

UIImage+DTFoundation.h

tileImageAtColumn:ofColumns:row:ofRows:

Cuts out a tile at the given row and column

- (UIImage *)tileImageAtColumn:(NSUInteger)column ofColumns:(NSUInteger)columns row:(NSUInteger)row ofRows:(NSUInteger)rows

Parameters

column

The index of the column

columns

The total number of columns

row

The index of the row

rows

The total number of rows

Return Value

The resulting image

Declared In

UIImage+DTFoundation.h

tileImageInClipRect:inBounds:scale:

Cuts out a tile at the given clip rect relative to the bounds

- (UIImage *)tileImageInClipRect:(CGRect)clipRect inBounds:(CGRect)bounds scale:(CGFloat)scale

Parameters

clipRect

The clipping rect to extract

bounds

The bounds to which the clipRect is relative to

scale

The image scale

Return Value

The resulting image

Declared In

UIImage+DTFoundation.h