Contents

preparingThumbnail(of:)

Returns a new thumbnail image at the specified size.

Declaration

func preparingThumbnail(of size: CGSize) -> UIImage?

Parameters

  • size:

    The desired size of the thumbnail.

Return Value

A new thumbnail image. Returns nil if the original image isn’t backed by a CGImage or if the image data is corrupt or malformed.

Discussion

When displaying an image in a UIImageView, you can use the view’s contentMode property to clip or scale the image automatically. But when the native image size is much larger than the bounds of the view, decoding the full size image creates unnecessary memory overhead. By creating a thumbnail image at a specified size with this method, you avoid the overhead of decoding the image at its full size.

See Also

Loading images for display