Mac Developer Library

Developer

AppKit Framework Reference NSRulerMarker Class Objective-C Reference

Options
Deployment Target:

On This Page
Language:

NSRulerMarker

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 ruler: NSRulerView, markerLocation location: CGFloat, image image: 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 movable and removable to change these attributes. The new ruler marker also has no represented object; use representedObject to set one.

    This method is the designated initializer for the NSRulerMarker class.

    Availability

    Available in OS X v10.0 and later.

  • The receiver's ruler view. (read-only)

    Declaration

    Swift

    unowned(unsafe) var ruler: NSRulerView { get }

    Objective-C

    @property(readonly, assign) NSRulerView *ruler

    Availability

    Available in OS X v10.0 and later.

  • The receiver’s image.

    Declaration

    Swift

    var image: NSImage

    Objective-C

    @property(strong) NSImage *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.

    Availability

    Available in OS X v10.0 and later.

    See Also

    imageOrigin

  • 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

    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.

    Availability

    Available in OS X v10.0 and later.

  • The rectangle occupied by the receiver’s image. (read-only)

    Declaration

    Swift

    var imageRectInRuler: NSRect { get }

    Objective-C

    @property(readonly) NSRect imageRectInRuler

    Discussion

    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.

    Availability

    Available in OS X v10.0 and later.

  • The amount of the receiver’s image that’s displayed above or to the left of the ruler view's baseline. (read-only)

    Declaration

    Swift

    var thicknessRequiredInRuler: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat thicknessRequiredInRuler

    Discussion

    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.

    Availability

    Available in OS X v10.0 and later.

    See Also

    imageOrigin

  • A boolean which indicates whether the user can move the receiver in its ruler view.

    Declaration

    Swift

    var movable: Bool

    Objective-C

    @property(getter=isMovable) BOOL movable

    Discussion

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

    By default ruler markers are movable.

    Availability

    Available in OS X v10.0 and later.

    See Also

    removable

  • A boolean that indicates whether the user can remove the receiver from its ruler view.

    Declaration

    Swift

    var removable: Bool

    Objective-C

    @property(getter=isRemovable) BOOL removable

    Discussion

    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.

    By default ruler markers are not removable.

    Availability

    Available in OS X v10.0 and later.

    See Also

    movable

  • 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

    Discussion

    This is an x position for a horizontal ruler, a y position for a vertical ruler.

    Availability

    Available in OS X v10.0 and later.

    See Also

    imageOrigin

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

    Declaration

    Swift

    func drawRect(_ rect: NSRect)

    Objective-C

    - (void)drawRect:(NSRect)aRect

    Parameters

    aRect

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

    Availability

    Available in OS X v10.0 and later.

    See Also

    imageRectInRuler

  • A Boolean that indicates whether the receiver is being dragged. (read-only)

    Declaration

    Swift

    var dragging: Bool { get }

    Objective-C

    @property(getter=isDragging, readonly) BOOL dragging

    Discussion

    YEStrue if the receiver is being dragged, NOfalse otherwise.

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func trackMouse(_ mouseDownEvent: NSEvent, adding isAdding: 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.

    Availability

    Available in OS X v10.0 and later.

    See Also

    movable
    removable