Mac Developer Library

Developer

AppKit Framework Reference NSCustomImageRep Class Reference

Options
Deployment Target:

On This Page
Language:

NSCustomImageRep

Inheritance


Conforms To


Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.0 and later.

An NSCustomImageRep object uses a delegate object to render an image. When called upon to produce an image, it sends a message to its delegate to do the actual drawing. You can use this class to support custom image formats without going to the trouble of subclassing NSImageRep directly.

  • Returns an NSCustomImageRep object initialized with the specified delegate information.

    Declaration

    Swift

    init(drawSelector aMethod: Selector, delegate anObject: AnyObject)

    Objective-C

    - (instancetype)initWithDrawSelector:(SEL)aMethod delegate:(id)anObject

    Parameters

    aMethod

    The selector to call when it is time to draw the image. The method should take a single parameter of type id that represents the NSCustomImageRep object that initiated drawing. The method must draw the image starting at the point (0, 0) in the current coordinate system.

    anObject

    The delegate object that responds to the selector in aMethod.

    Return Value

    An initialized NSCustomImageRep object, or nil if the object could not be initialized.

    Discussion

    When the receiver is asked to draw the image, it sends the specified message to the selector, passing itself as a parameter to the delegate method. The delegate's drawing method should have the following form:

    • - (void)myCustomDrawMethod:(id)anNSCustomImageRep;

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    draw (NSImageRep)

  • Initializes an image representation of the specified size and flipped status, using a Block to draw its content.

    Declaration

    Swift

    init(size size: NSSize, flipped drawingHandlerShouldBeCalledWithFlippedContext: Bool, drawingHandler drawingHandler: (NSRect) -> Bool)

    Objective-C

    - (instancetype)initWithSize:(NSSize)size flipped:(BOOL)drawingHandlerShouldBeCalledWithFlippedContext drawingHandler:(BOOL (^)(NSRect dstRect))drawingHandler

    Parameters

    size

    The size of the image.

    drawingHandlerShouldBeCalledWithFlippedContext

    YEStrue if the drawing handler should be called with a flipped graphics context; otherwise NOfalse.

    drawingHandler

    A Block that draws the image rep content in the provided graphics context.

    The block may be invoked whenever and on whatever thread the image itself is drawn on. Care should be taken to ensure that all state accessed within the drawingHandler block is done so in a thread safe manner.

    This Block replaces the lockFocus and unlockFocus technique of creating drawing content. The block is invoked at draw time, the drawing can be adjusted to suit the destination’s pixel density, color space, and other properties.

    Return Value

    An initialized NSCustomImageRep object, or nil if the object could not be initialized.

    Discussion

    Using the this method ensures you’ll get correct results under standard and high resolution.

    Like other non-bitmap image rep types, drawing is cached as appropriate for the destination context. Practically speaking, the drawingHandler block will be invoked the first time the image is drawn to a particular type of destination (1x or 2x screen, for example). Subsequent drawing operations to the same type of destination will reuse the previously generated bitmap.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.8 and later.

  • Returns the destination rectangle of the drawing handler Block.

    Declaration

    Swift

    var drawingHandler: ((NSRect) -> Bool)? { get }

    Objective-C

    @property(readonly, copy) BOOL (^drawingHandler)(NSRect)

    Return Value

    The destination rectangle of the drawing handler Block.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.8 and later.

  • Returns the delegate object that renders the image for the receiver.

    Declaration

    Swift

    unowned(unsafe) var delegate: AnyObject? { get }

    Objective-C

    @property(readonly, assign) id delegate

    Return Value

    The delegate object.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the selector for the delegate's drawing method.

    Declaration

    Swift

    var drawSelector: Selector { get }

    Objective-C

    @property(readonly) SEL drawSelector

    Return Value

    The selector for the delegate's drawing method.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.