Mac Developer Library

Developer

AppKit Framework Reference NSRulerMarker Class Objective-C Reference

Options
Deployment Target:

On This Page
Language:

NSRulerMarker

Inheritance


Conforms To


Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.0 and later.

An NSRulerMarker object displays a symbol on an NSRulerView object, indicating a location for whatever graphics element it represents in the client of the ruler view (for example, a margin or tab setting, or the edges of a graphic on the page).

  • Initializes a newly allocated ruler marker, associating it with (but not adding it to) a specified ruler view and assigning the attributes provided.

    Declaration

    Swift

    init(rulerView aRulerView: NSRulerView, markerLocation location: CGFloat, image anImage: NSImage, imageOrigin imageOrigin: NSPoint)

    Objective-C

    - (instancetype)initWithRulerView:(NSRulerView *)aRulerView markerLocation:(CGFloat)location image:(NSImage *)anImage imageOrigin:(NSPoint)imageOrigin

    Parameters

    aRulerView

    The ruler view with which to associate the ruler marker. This method raises an NSInvalidArgumentException if aRulerView is nil.

    location

    The x or y position of the marker in the client view’s coordinate system, depending on whether the ruler view is horizontal or vertical.

    anImage

    The image displayed at the marker location. This method raises an NSInvalidArgumentException if anImage is nil.

    imageOrigin

    The point within the image positioned at the marker location, expressed in pixels relative to the lower-left corner of the image.

    Return Value

    An initialized ruler marker object.

    Discussion

    The image used to draw the marker must be appropriate for the orientation of the ruler. Markers may need to look different on a horizontal ruler than on a vertical ruler, and the ruler view neither scales nor rotates the images.

    To add the new ruler marker to aRulerView, use either of NSRulerView’s addMarker: or trackMarker:withMouseEvent: methods. addMarker: immediately puts the marker on the ruler, while trackMarker:withMouseEvent: allows the client view to intercede in the addition and placement of the marker.

    A new ruler marker can be moved on its ruler view, but not removed. Use setMovable: and setRemovable: to change these attributes. The new ruler marker also has no represented object; use setRepresentedObject: to set one.

    This method is the designated initializer for the NSRulerMarker class.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the receiver's ruler view.

    Declaration

    Swift

    unowned(unsafe) var ruler: NSRulerView { get }

    Objective-C

    @property(readonly, assign) NSRulerView *ruler

    Return Value

    The receiver's ruler view.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – addMarker: (NSRulerView)

  • Sets the receiver’s image.

    Declaration

    Swift

    var image: NSImage

    Objective-C

    @property(strong) NSImage *image

    Parameters

    anImage

    The new image.

    Discussion

    The image used to draw the marker must be appropriate for the orientation of the ruler. Markers may need to look different on a horizontal ruler than on a vertical ruler, and the ruler view neither scales nor rotates the images.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the image displayed by the receiver.

    Declaration

    Swift

    var image: NSImage

    Objective-C

    @property(strong) NSImage *image

    Return Value

    The image displayed by the receiver.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – setImage:

  • Sets the point in the receiver’s image that is positioned at the receiver’s location on the ruler view.

    Declaration

    Swift

    var imageOrigin: NSPoint

    Objective-C

    @property NSPoint imageOrigin

    Parameters

    aPoint

    The point within the image positioned at the marker location, expressed in pixels relative to the lower-left corner of the image.

    Discussion

    For a horizontal ruler, the x coordinate of the image origin is aligned with the location of the marker, and the y coordinate lies on the baseline of the ruler. For vertical rulers, the y coordinate of the image origin is the location, and the x coordinate lies on the baseline.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the point in the receiver’s image positioned at the receiver’s location on the ruler view.

    Declaration

    Swift

    var imageOrigin: NSPoint

    Objective-C

    @property NSPoint imageOrigin

    Return Value

    The point in the receiver’s image positioned at the receiver’s location on the ruler view, expressed in the image’s coordinate system.

    Discussion

    For a horizontal ruler, the x coordinate of the image origin is aligned with the location of the marker, and the y coordinate lies on the baseline of the ruler. For vertical rulers, the y coordinate of the image origin is the location, and the x coordinate lies on the baseline.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the rectangle occupied by the receiver’s image.

    Declaration

    Swift

    var imageRectInRuler: NSRect { get }

    Objective-C

    @property(readonly) NSRect imageRectInRuler

    Return Value

    The rectangle occupied by the receiver’s image, in the ruler view's coordinate system, accounting for whether the ruler view's coordinate system is flipped.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the amount of the receiver’s image that’s displayed above or to the left of the ruler view's baseline.

    Declaration

    Swift

    var thicknessRequiredInRuler: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat thicknessRequiredInRuler

    Return Value

    The amount of the receiver’s image that’s displayed above or to the left of the ruler view's baseline, the height for a horizontal ruler or width for a vertical ruler.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – imageOrigin

  • Sets whether the user can move the receiver in its ruler view.

    Declaration

    Swift

    var movable: Bool

    Objective-C

    @property(getter=isMovable) BOOL movable

    Parameters

    flag

    YEStrue to allow the user to drag the marker image in the ruler, NOfalse to make it immobile.

    Discussion

    By default ruler markers are movable.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • isMovable - isMovable Available in OS X v10.0 through OS X v10.9

    Returns whether the user can move the receiver on its ruler view.

    Declaration

    Objective-C

    - (BOOL)isMovable

    Return Value

    YEStrue if the user can move the receiver on its ruler view, NOfalse otherwise.

    Discussion

    By default ruler markers are movable.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 through OS X v10.9.

  • Sets whether the user can remove the receiver from its ruler view.

    Declaration

    Swift

    var removable: Bool

    Objective-C

    @property(getter=isRemovable) BOOL removable

    Parameters

    flag

    YEStrue to allow the user to drag the marker image off of the ruler and remove the marker, NOfalse to prevent the user from removing the marker.

    Discussion

    By default ruler markers are not removable.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • isRemovable - isRemovable Available in OS X v10.0 through OS X v10.9

    Returns whether the user can remove the receiver from its ruler view.

    Declaration

    Objective-C

    - (BOOL)isRemovable

    Return Value

    YEStrue if the user can remove the receiver from its ruler view, NOfalse otherwise.

    Discussion

    By default ruler markers are not removable.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 through OS X v10.9.

  • Sets the location of the receiver in the coordinate system of the ruler view's client view.

    Declaration

    Swift

    var markerLocation: CGFloat

    Objective-C

    @property CGFloat markerLocation

    Parameters

    location

    The location of the receiver in the coordinate system of the ruler view's client view. This is an x position for a horizontal ruler, a y position for a vertical ruler.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the location of the receiver in the coordinate system of the ruler view's client view.

    Declaration

    Swift

    var markerLocation: CGFloat

    Objective-C

    @property CGFloat markerLocation

    Return Value

    The location of the receiver in the coordinate system of the ruler view's client view. This is an x position for a horizontal ruler, a y position for a vertical ruler.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the object the receiver represents.

    Declaration

    Swift

    var representedObject: NSCopying?

    Objective-C

    @property(strong) id<NSCopying> representedObject

    Parameters

    anObject

    The new represented object.

    Discussion

    See About Ruler Markers for more information on the represented object.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the object the receiver represents.

    Declaration

    Swift

    var representedObject: NSCopying?

    Objective-C

    @property(strong) id<NSCopying> representedObject

    Return Value

    The object the receiver represents.

    Discussion

    See About Ruler Markers for more information on the represented object.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Draws the receiver’s image that appears in the supplied rectangle.

    Declaration

    Swift

    func drawRect(_ aRect: NSRect)

    Objective-C

    - (void)drawRect:(NSRect)aRect

    Parameters

    aRect

    The rectangle to be drawn, in the ruler view's coordinate system.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • isDragging - isDragging Available in OS X v10.0 through OS X v10.9

    Returns whether the receiver is being dragged.

    Declaration

    Objective-C

    - (BOOL)isDragging

    Return Value

    YEStrue if the receiver is being dragged, NOfalse otherwise.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 through OS X v10.9.

  • Handles user manipulation of the receiver in its ruler view.

    Declaration

    Swift

    func trackMouse(_ theEvent: NSEvent, adding flag: Bool) -> Bool

    Objective-C

    - (BOOL)trackMouse:(NSEvent *)theEvent adding:(BOOL)flag

    Parameters

    theEvent

    The event that represents the user manipulation being attempted on the ruler marker.

    flag

    YEStrue to indicate that the receiver is a new marker being added to its ruler view, NOfalse otherwise.

    Return Value

    YEStrue if the user manipulation was allowed, NOfalse if it was not allowed.

    Discussion

    NSRulerView objects invoke this method automatically to add a new marker or to move or remove an existing marker. You should never need to invoke it directly.

    If the receiver is a new marker being added to its ruler view (flag is YEStrue), the receiver queries the ruler view's client before adding itself to the ruler view. If the client responds to rulerView:shouldAddMarker: and that method returns NOfalse, this method immediately returns NOfalse, and the new marker isn’t added.

    If the receiver is not a new marker being added to its ruler view (flag is NOfalse), this method attempts to move or remove an existing marker, once again based on responses from the ruler view's client view. If the receiver is neither movable nor removable, this method immediately returns NOfalse. Further, if the ruler view's client responds to rulerView:shouldMoveMarker: and returns NOfalse, this method returns NOfalse, indicating the receiver can’t be moved.

    If the receiver is being added or moved, this method queries the client view using rulerView:willAddMarker:atLocation: or rulerView:willMoveMarker:toLocation:, respectively. If the client responds to the method, the return value is used as the receiver’s location. These methods are invoked repeatedly as the receiver is dragged within the ruler view.

    If the receiver is an existing marker being removed (dragged off the ruler), this method queries the client view using rulerView:shouldRemoveMarker:. If the client responds to this method and returns NOfalse, the marker is pinned to the ruler view's baseline (following the cursor on the baseline if it’s movable).

    When the user releases the mouse button, this method informs the client view of the marker’s new status using rulerView:didAddMarker:, rulerView:didMoveMarker:, or rulerView:didRemoveMarker: as appropriate. The client view can use this notification to set the marker’s represented object, modify its state and redisplay (for example, adjusting text layout around a new tab stop), or take whatever other action it might need.

    If flag is YEStrue and the user dragged the new marker away from the ruler, the marker isn’t added, no message is sent, and this method returns NOfalse.

    See Ruler and Paragraph Style Programming Topics for more information on these client methods.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.