An NSRulerView displays a ruler and markers above or to the side of an NSScrollView’s document view. Views within the NSScrollView can become clients of the ruler view, having it display markers for their elements, and receiving messages from the ruler view when the user manipulates the markers.


Principal Attributes

  • Displays markers that represent elements of the client view.

  • Displays in arbitrary units.

  • Provides for an accessory view containing extra controls.


Commonly Used Methods


Changes the ruler’s client view.


Sets the markers displayed by the ruler view.


Sets the accessory view.


Allows the user to add a new marker.


See NSRulerMarkerClientViewDelegation for delegate methods that may be of interest.


Creating instances

init(scrollView: NSScrollView?, orientation: NSRulerOrientation)

Initializes a newly allocated NSRulerView to have orientation (NSHorizontalRuler or NSVerticalRuler) within aScrollView.

Altering measurement units

class func registerUnit(withName: String, abbreviation: String, unitToPointsConversionFactor: CGFloat, stepUpCycle: [NSNumber], stepDownCycle: [NSNumber])

Registers a new unit of measurement with the NSRulerView class, making it available to all instances of NSRulerView.

var measurementUnits: String

The measurement units used by the ruler to unitName.

Setting the client view

var clientView: NSView?

The receiver’s client view, if it has one.

Setting an accessory view

var accessoryView: NSView?

The receiver’s accessory view to aView.

Setting the zero mark position

var originOffset: CGFloat

The distance to the zero hash mark from the bounds origin of the NSScrollView’s document view (not of the receiver’s client view), in the document view’s coordinate system.

Adding and removing markers

var markers: [NSRulerMarker]?

The receiver’s ruler markers to markers, removing any existing ruler markers and not consulting with the client view about the new markers.

func addMarker(NSRulerMarker)

Adds aMarker to the receiver, without consulting the client view for approval.

func removeMarker(NSRulerMarker)

Removes aMarker from the receiver, without consulting the client view for approval.

func trackMarker(NSRulerMarker, withMouseEvent: NSEvent)

Tracks the mouse to add aMarker based on the initial mouse-down or mouse-dragged event theEvent.

Drawing temporary ruler lines


func drawHashMarksAndLabels(in: NSRect)

Draws the receiver’s hash marks and labels in aRect, which is expressed in the receiver’s coordinate system.

func drawMarkers(in: NSRect)

Draws the receiver’s markers in aRect, which is expressed in the receiver’s coordinate system.

func invalidateHashMarks()

Forces recalculation of the hash mark spacing for the next time the receiver is displayed.

Ruler layout

var scrollView: NSScrollView?

The NSScrollView that owns the receiver to scrollView, without retaining it.

var orientation: NSRulerOrientation

The orientation of the receiver to orientation.

var reservedThicknessForAccessoryView: CGFloat

The room available for the receiver’s accessory view to thickness.

var reservedThicknessForMarkers: CGFloat

The room available for ruler markers to thickness.

var ruleThickness: CGFloat

The thickness of the area where ruler hash marks and labels are drawn.

var requiredThickness: CGFloat

The thickness needed for proper tiling of the receiver within an NSScrollView.

var baselineLocation: CGFloat

The location of the receiver’s baseline, in its own coordinate system.

var isFlipped: Bool

A boolean that indicates if the NSRulerView’s coordinate system is flipped.



These constants are defined to specify a ruler’s orientation and are used by orientation.


Inherits From

Conforms To