SDGraphicsImageRenderer

@interface SDGraphicsImageRenderer : NSObject

A graphics renderer for creating Core Graphics-backed images.

  • Creates an image renderer for drawing images of a given size.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithSize:(CGSize)size;

    Swift

    init(size: CGSize)

    Parameters

    size

    The size of images output from the renderer, specified in points.

    Return Value

    An initialized image renderer.

  • Creates a new image renderer with a given size and format.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithSize:(CGSize)size
                                  format:(nonnull SDGraphicsImageRendererFormat *)
                                             format;

    Swift

    init(size: CGSize, format: SDGraphicsImageRendererFormat)

    Parameters

    size

    The size of images output from the renderer, specified in points.

    format

    A SDGraphicsImageRendererFormat object that encapsulates the format used to create the renderer context.

    Return Value

    An initialized image renderer.

  • Creates an image by following a set of drawing instructions.

    Note

    You should not retain or use the context outside the block, it’s non-escaping.

    Declaration

    Objective-C

    - (nonnull UIImage *)imageWithActions:
        (nonnull SDGraphicsImageDrawingActions)actions;

    Swift

    func image(actions: (CGContext) -> Void) -> UIImage

    Parameters

    actions

    A SDGraphicsImageDrawingActions block that, when invoked by the renderer, executes a set of drawing instructions to create the output image.

    Return Value

    A UIImage object created by the supplied drawing actions.