问题
I am making an image editing application, but it looks very incomplete without a cursor like they have in Photoshop for the paintbrush. How can I set the icon, and have it change back when I exit the application?
This is the code in my header file (just in case it's needed):
@interface test : NSWindow <NSWindowDelegate> {
IBOutlet id myView;
}
@end
myView is an NSView
(customView) that will display everything.
回答1:
There's a handy NSCursor class for handling cursor appearance. If one of the built-in cursors doesn't look how you need it to, you can initialize a new NSCursor
with an NSImage
and -set
it to be the active cursor.
回答2:
If the drawing area is rectangular(NSTracking Areas are always rectangular) :- Use the mouseEntered,mouse Exited methods of NSTrackingArea to track and change the mouse cursor.The mouse cursor could be changed using NSCursor class.
If the tracking area is not rectangular then make a bigger rectangular tracking area enclosing the whole drawing region and then track the mouseMoved events inside the tracking area to set the cursor appropriately . Refer to apple documentation for more details.
来源:https://stackoverflow.com/questions/5544757/how-to-change-the-mouse-cursor-in-objective-c