Next Page > Hide TOC

NSCursor Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/AppKit.framework
Availability
Available in Mac OS X v10.0 and later.
Companion guide
Declared in
NSCursor.h
Related sample code

Overview

Instances of the NSCursor class manage the appearance of the cursor.

The following table shows and describes the system cursors, and indicates the class method for obtaining them:

Cursor

Description

arrow cursor

The arrow cursor (arrowCursor)

I-beam cursor

The I-beam cursor for indicating insertion points (IBeamCursor)

cross-hair cursor

The cross-hair cursor (crosshairCursor)

closed-hand cursor

The closed-hand cursor (closedHandCursor)

open-hand cursor

The open-hand cursor (openHandCursor)

pointing hand cursor

The pointing-hand cursor (pointingHandCursor)

resize-left cursor

The resize-left cursor (resizeLeftCursor)

resize-right cursor

The resize-right cursor (resizeRightCursor)

resize-left-and-right cursor

The resize-left-and-right cursor (resizeLeftRightCursor)

resize-up cursor

The resize-up cursor (resizeUpCursor)

resize-down cursor

The resize-down cursor (resizeDownCursor)

resize-up-and-down cursor

The resize-up-and-down cursor (resizeUpDownCursor)

disappearing item cursor

The disappearing item cursor (disappearingItemCursor)

In Mac OS X version 10.3 and later, cursor size is no longer limited to 16 by 16 pixels.

Cursor Rectangles

In Cocoa, you can change the currently displayed cursor based on the position of the mouse over one of your views. You might use this technique to provide visual feedback about what actions the user can take with the mouse. For example, you might display one of the resize cursors whenever the mouse moves over a portion of your view that acts as a custom resizing handle. To set this up, you associate a cursor object with one or more cursor rectangles in the view.

Cursor rectangles are a specialized type of tracking rectangles, which are used to monitor the mouse location in a view. Views implement cursor rectangles using tracking rectangles but provide methods for setting and refreshing cursor rectangles that are distinct from the generic tracking rectangle interface. For information on how to set up cursor rectangles, see “Handling Tracking-Rectangle and Cursor-Update Events in Views”.

Adopted Protocols

NSCoding

Tasks

Initializing a New Cursor

Setting Cursor Attributes

Controlling Which Cursor Is Current

Retrieving Cursor Instances

Class Methods

arrowCursor

Returns the default cursor, the arrow cursor.

+ (NSCursor *)arrowCursor

Return Value

The default cursor, a slanted arrow with its hot spot at the tip. The arrow cursor is the one you’re used to seeing over buttons, scrollers, and many other objects in the window system.

Availability
See Also
Related Sample Code
Declared In
NSCursor.h

closedHandCursor

Returns the closed-hand system cursor.

+ (NSCursor *)closedHandCursor

Return Value

The closed-hand cursor.

Availability
Related Sample Code
Declared In
NSCursor.h

crosshairCursor

Returns the cross-hair system cursor.

+ (NSCursor *)crosshairCursor

Return Value

The cross-hair cursor. This cursor is used for situations when precise location is required (where the lines cross is the hot spot).

Availability
Related Sample Code
Declared In
NSCursor.h

currentCursor

Returns the application’s current cursor.

+ (NSCursor *)currentCursor

Return Value

The top cursor on the application’s cursor stack. This cursor may not be the visible cursor on the screen if a different application is currently active.

Availability
See Also
Declared In
NSCursor.h

disappearingItemCursor

Returns a cursor indicating that the current operation will result in a disappearing item.

+ (NSCursor *)disappearingItemCursor

Return Value

The system cursor that indicates that the current operation will result in a disappearing item (for example, when dragging an item from the dock or a toolbar).

Availability
Declared In
NSCursor.h

hide

Makes the current cursor invisible.

+ (void)hide

Discussion

If another cursor becomes current, that cursor will be invisible, too. It will remain invisible until you invoke the unhide method.

hide overrides setHiddenUntilMouseMoves:.

Availability
Related Sample Code
Declared In
NSCursor.h

IBeamCursor

Returns a cursor that looks like a capital I with a tiny crossbeam at its middle.

+ (NSCursor *)IBeamCursor

Return Value

The I-beam cursor. This is the cursor that you’re used to seeing over editable or selectable text. The I-beam cursor’s default hot spot is where the crossbeam intersects the I.

Availability
See Also
Declared In
NSCursor.h

openHandCursor

Returns the open-hand system cursor.

+ (NSCursor *)openHandCursor

Return Value

The open-hand cursor.

Availability
Related Sample Code
Declared In
NSCursor.h

pointingHandCursor

Returns the pointing-hand system cursor.

+ (NSCursor *)pointingHandCursor

Return Value

The pointing-hand cursor. The tip of the pointing finger is the hot spot.

Availability
Related Sample Code
Declared In
NSCursor.h

pop

Pops the current cursor off the top of the stack.

+ (void)pop

Discussion

The new object on the top of the stack becomes the current cursor. If the current cursor is the only cursor on the stack, this method does nothing.

Availability
See Also
Related Sample Code
Declared In
NSCursor.h

resizeDownCursor

Returns the resize-down system cursor.

+ (NSCursor *)resizeDownCursor

Return Value

The resize-down cursor. This cursor is used when moving or resizing an object to indicate that the user can move only in the indicated direction.

Availability
Declared In
NSCursor.h

resizeLeftCursor

Returns the resize-left system cursor.

+ (NSCursor *)resizeLeftCursor

Return Value

The resize-left cursor. This cursor is used when moving or resizing an object to indicate that the user can move only in the indicated direction.

Availability
Declared In
NSCursor.h

resizeLeftRightCursor

Returns the resize-left-and-right system cursor.

+ (NSCursor *)resizeLeftRightCursor

Return Value

The resize-left-and-right cursor. This cursor is used when moving or resizing an object and the object can be moved left or right.

Availability
Declared In
NSCursor.h

resizeRightCursor

Returns the resize-right system cursor.

+ (NSCursor *)resizeRightCursor

Return Value

The resize-right cursor. This cursor is used when moving or resizing an object to indicate that the user can move only in the indicated direction.

Availability
Declared In
NSCursor.h

resizeUpCursor

Returns the resize-up system cursor.

+ (NSCursor *)resizeUpCursor

Return Value

The resize-up cursor. This cursor is used when moving or resizing an object to indicate that the user can move only in the indicated direction.

Availability
Declared In
NSCursor.h

resizeUpDownCursor

Returns the resize-up-and-down system cursor.

+ (NSCursor *)resizeUpDownCursor

Return Value

The resize-up-and-down cursor. This cursor is used when moving or resizing an object and the object can be moved up or down.

Availability
Declared In
NSCursor.h

setHiddenUntilMouseMoves:

Sets whether the cursor is hidden until the mouse moves.

+ (void)setHiddenUntilMouseMoves:(BOOL)flag

Parameters
flag

YES to hide the cursor until one of the following occurs:

  • The mouse moves.

  • You invoke the method again, with flag set to NO.

Discussion

Do not try to counter this method by invoking unhide. The results are undefined.

Availability
See Also
Declared In
NSCursor.h

unhide

Negates an earlier call to hide by showing the current cursor.

+ (void)unhide

Availability
See Also
Related Sample Code
Declared In
NSCursor.h

Instance Methods

hotSpot

Returns the position of the cursor's hot spot.

- (NSPoint)hotSpot

Return Value

The point describing the position of the hot spot, specified according to the cursor’s flipped coordinate system.

Discussion

For a more complete explanation, see the class description.

Note that an NSCursor object is immutable: you cannot change its hot spot after it’s created. Instead, use initWithImage:hotSpot: to create a new cursor with the new settings.

Availability
See Also
Declared In
NSCursor.h

image

Returns the receiver's image.

- (NSImage *)image

Return Value

The cursor image or nil if none exists

Discussion

Note that an NSCursor object is immutable: you cannot change its image after it’s created. Instead, use initWithImage:hotSpot: to create a new cursor with the new settings.

Availability
See Also
Declared In
NSCursor.h

initWithImage:foregroundColorHint:backgroundColorHint:hotSpot:

Initializes the cursor with the specified image and hot spot.

- (id)initWithImage:(NSImage *)newImage foregroundColorHint:(NSColor *)fg backgroundColorHint:(NSColor *)bg hotSpot:(NSPoint)hotSpot

Parameters
newImage

The image to assign to the cursor.

fg

The foreground color. This is currently ignored.

bg

The background color. This is currently ignored.

hotSpot

The point to assign as the cursor's hot spot.

Return Value

The initialized cursor object.

Availability
See Also
Declared In
NSCursor.h

initWithImage:hotSpot:

Initializes a cursor with the given image and hot spot.

- (id)initWithImage:(NSImage *)newImage hotSpot:(NSPoint)aPoint

Parameters
newImage

The image to assign to the cursor.

aPoint

The point to set as the cursor's hot spot.

Return Value

An initialized cursor object.

Discussion

This method is the designated initializer for the class.

Availability
See Also
Related Sample Code
Declared In
NSCursor.h

isSetOnMouseEntered

Returns a Boolean value indicating whether the receiver becomes current on receiving a mouseEntered: message.

- (BOOL)isSetOnMouseEntered

Return Value

YES if the receiver will become current when it receives a mouseEntered: message; otherwise, NO.

Discussion

To receive such a message, the receiver must first be assigned a cursor rectangle. This assignment can be made using the NSView method addCursorRect:cursor:. For a more complete explanation, see the class description.

Availability
See Also
Declared In
NSCursor.h

isSetOnMouseExited

Returns a Boolean value indicating whether the receiver becomes current when it receives a mouseExited: message.

- (BOOL)isSetOnMouseExited

Return Value

YES if the receiver becomes current when it receives a mouseExited: message; otherwise, NO.

Discussion

To receive such a message, the receiver must first be assigned a cursor rectangle. This assignment can be made using the NSView method addCursorRect:cursor:. For a more complete explanation, see the class description.

Availability
See Also
Declared In
NSCursor.h

mouseEntered:

Automatically sent to the receiver when the cursor enters a cursor rectangle owned by the receiver.

- (void)mouseEntered:(NSEvent *)anEvent

Parameters
anEvent

The event generated when the cursor enters the cursor rectangle.

Discussion

If used after setOnMouseEntered: has been called with an argument of YES, mouseEntered: can make the receiver the current cursor.

In your programs, you won’t invoke mouseEntered: explicitly. It’s only included in the class interface so you can override it.

For a more complete explanation, see “Handling Tracking-Rectangle and Cursor-Update Events in Views” and the NSView method addTrackingRect:owner:userData:assumeInside:.

Availability
See Also
Declared In
NSCursor.h

mouseExited:

Automatically sent to the receiver when the cursor exits a cursor rectangle owned by the receiver.

- (void)mouseExited:(NSEvent *)anEvent

Parameters
anEvent

The event generated when the cursor exits the cursor rectangle.

Discussion

Like mouseEntered:, this message is part of the class interface only so you can override it.

For a more complete explanation, see “Handling Tracking-Rectangle and Cursor-Update Events in Views” and the NSView method addTrackingRect:owner:userData:assumeInside:.

Availability
See Also
Declared In
NSCursor.h

pop

Sends a pop message to the receiver’s class.

- (void)pop

Availability
See Also
Declared In
NSCursor.h

push

Puts the receiver on top of the cursor stack and makes it the current cursor.

- (void)push

Availability
See Also
Related Sample Code
Declared In
NSCursor.h

set

Makes the receiver the current cursor.

- (void)set

Availability
See Also
Related Sample Code
Declared In
NSCursor.h

setOnMouseEntered:

Specifies whether the receiver accepts mouseEntered: events.

- (void)setOnMouseEntered:(BOOL)flag

Parameters
flag

YES if the receiver accepts future mouseEntered: event messages; otherwise it ignores them.

Discussion

Accepting mouseEntered: event messages allows the cursor to be made the current cursor when the cursor enters a view’s cursor rectangle.

Availability
See Also
Declared In
NSCursor.h

setOnMouseExited:

Sets whether the receiver accepts mouseExited: events.

- (void)setOnMouseExited:(BOOL)flag

Parameters
flag

YES if the receiver accepts future mouseExited: event messages; otherwise it ignores them.

Discussion

Accepting mouseExited: event messages allows the cursor to be made the current cursor when the cursor exits a view’s cursor rectangle.

Availability
Declared In
NSCursor.h

Constants

AppKit Versions for NSCursor Bug Fixes

The version of the AppKit framework containing a specific bug fix.

#define NSAppKitVersionNumberWithCursorSizeSupport 682.0

Constants
NSAppKitVersionNumberWithCursorSizeSupport

The specific version of the AppKit framework that introduced support for cursors larger than 16 x 16 pixels in size. Developers should not need to use this constant unless they are writing applications for Mac OS X v10.2 and earlier.

Available in Mac OS X v10.3 and later.

Declared in NSCursor.h.



Next Page > Hide TOC


© 2009 Apple Inc. All Rights Reserved. (Last updated: 2009-01-06)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.