Date
Dec. 26th, 2024
 
2024年 11月 26日

Post: Cocoa: Change Cursor

Cocoa: Change Cursor

Published 12:05 May 10, 2016.

Created by @ezra. Categorized in #Programming, and tagged as #macOS.

Source format: Markdown

Table of Content

The way to change the cursor when it's over an NSButton:

  • First, you should subclass NSButton first, then add the code below:
@property (strong) NSCursor *cursor;

- (void)resetCursorRects {
    if (self.cursor) {
        [self addCursorRect:[self bounds] cursor: self.cursor];
    } else {
        [super resetCursorRects];
    }
}
  • Now, set cursor as you like:
[self.button setCursor:[NSCursor pointingHandCursor]];
Pinned Message
HOTODOGO
The Founder and CEO of Infeca Technology.
Developer, Designer, Blogger.
Big fan of Apple, Love of colour.
Feel free to contact me.
反曲点科技创始人和首席执行官。
开发、设计与写作皆为所长。
热爱苹果、钟情色彩。
随时恭候 垂询