<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSRulerView",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSRulerView"
  },
  "title" : "NSRulerView"
}
-->

# NSRulerView

A ruler and the markers above or to the side of a scroll view’s document view.

```
class NSRulerView
```

## Overview

Views within the scroll view 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.

### Creation

- [`hasHorizontalRuler`](/documentation/AppKit/NSScrollView/hasHorizontalRuler) (`NSScrollView`)
- [`hasVerticalRuler`](/documentation/AppKit/NSScrollView/hasVerticalRuler) (`NSScrollView`)
- [`init(scrollView:orientation:)`](/documentation/AppKit/NSRulerView/init(scrollView:orientation:)) Designated initializer.

### Commonly Used Methods

- [`clientView`](/documentation/AppKit/NSRulerView/clientView): Changes the ruler’s client view.
- [`markers`](/documentation/AppKit/NSRulerView/markers): Sets the markers displayed by the ruler view.
- [`accessoryView`](/documentation/AppKit/NSRulerView/accessoryView): Sets the accessory view.
- [`trackMarker(_:withMouseEvent:)`](/documentation/AppKit/NSRulerView/trackMarker(_:withMouseEvent:)): Allows the user to add a new marker.

### Overview

See NSRulerMarkerClientViewDelegation for delegate methods that may be of interest.

## Topics

### Creating a Ruler View

[`-  initWithScrollView:orientation:`](/documentation/AppKit/NSRulerView/init(scrollView:orientation:))

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

[`-  initWithCoder:`](/documentation/AppKit/NSRulerView/init(coder:))

### Altering measurement units

[`+  registerUnitWithName:abbreviation:unitToPointsConversionFactor:stepUpCycle:stepDownCycle:`](/documentation/AppKit/NSRulerView/registerUnit(withName:abbreviation:unitToPointsConversionFactor:stepUpCycle:stepDownCycle:))

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

[`measurementUnits`](/documentation/AppKit/NSRulerView/measurementUnits)

The measurement units used by the ruler to `unitName`.

[`UnitName`](/documentation/AppKit/NSRulerView/UnitName)

### Setting the client view

[`clientView`](/documentation/AppKit/NSRulerView/clientView)

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

### Setting an accessory view

[`accessoryView`](/documentation/AppKit/NSRulerView/accessoryView)

The receiver’s accessory view to `aView`.

### Setting the zero mark position

[`originOffset`](/documentation/AppKit/NSRulerView/originOffset)

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

[`markers`](/documentation/AppKit/NSRulerView/markers)

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

[`-  addMarker:`](/documentation/AppKit/NSRulerView/addMarker(_:))

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

[`-  removeMarker:`](/documentation/AppKit/NSRulerView/removeMarker(_:))

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

[`-  trackMarker:withMouseEvent:`](/documentation/AppKit/NSRulerView/trackMarker(_:withMouseEvent:))

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

### Drawing temporary ruler lines

[`-  moveRulerlineFromLocation:toLocation:`](/documentation/AppKit/NSRulerView/moveRulerline(fromLocation:toLocation:))

Draws temporary lines in the ruler area.

### Drawing

[`-  drawHashMarksAndLabelsInRect:`](/documentation/AppKit/NSRulerView/drawHashMarksAndLabels(in:))

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

[`-  drawMarkersInRect:`](/documentation/AppKit/NSRulerView/drawMarkers(in:))

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

[`-  invalidateHashMarks`](/documentation/AppKit/NSRulerView/invalidateHashMarks())

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

### Ruler layout

[`scrollView`](/documentation/AppKit/NSRulerView/scrollView)

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

[`orientation`](/documentation/AppKit/NSRulerView/orientation-swift.property)

The orientation of the receiver to `orientation`.

[`Orientation`](/documentation/AppKit/NSRulerView/Orientation-swift.enum)

These constants are defined to specify a ruler’s orientation and are used by [`orientation`](/documentation/AppKit/NSRulerView/orientation-swift.property).

[`reservedThicknessForAccessoryView`](/documentation/AppKit/NSRulerView/reservedThicknessForAccessoryView)

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

[`reservedThicknessForMarkers`](/documentation/AppKit/NSRulerView/reservedThicknessForMarkers)

The room available for ruler markers to `thickness`.

[`ruleThickness`](/documentation/AppKit/NSRulerView/ruleThickness)

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

[`requiredThickness`](/documentation/AppKit/NSRulerView/requiredThickness)

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

[`baselineLocation`](/documentation/AppKit/NSRulerView/baselineLocation)

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

[`flipped`](/documentation/AppKit/NSRulerView/isFlipped)

A Boolean that indicates if the ruler view’s coordinate system is flipped.

## Relationships

### Conforms To

[`NSCoding`](/documentation/Foundation/NSCoding)

[`NSAnimatablePropertyContainer`](/documentation/AppKit/NSAnimatablePropertyContainer)

[`NSStandardKeyBindingResponding`](/documentation/AppKit/NSStandardKeyBindingResponding)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`NSAppearanceCustomization`](/documentation/AppKit/NSAppearanceCustomization)

[`NSUserActivityRestoring`](/documentation/AppKit/NSUserActivityRestoring)

[`NSTouchBarProvider`](/documentation/AppKit/NSTouchBarProvider)

[`NSAccessibilityProtocol`](/documentation/AppKit/NSAccessibilityProtocol)

[`Sendable`](/documentation/Swift/Sendable)

[`NSAccessibilityElementProtocol`](/documentation/AppKit/NSAccessibilityElementProtocol)

[`NSUserInterfaceItemIdentification`](/documentation/AppKit/NSUserInterfaceItemIdentification)

[`Equatable`](/documentation/Swift/Equatable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`CVarArg`](/documentation/Swift/CVarArg)

[`Hashable`](/documentation/Swift/Hashable)

[`NSDraggingDestination`](/documentation/AppKit/NSDraggingDestination)

### Inherits From

[`NSView`](/documentation/AppKit/NSView)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)