Date
Sep. 8th, 2024
 
2024年 8月 6日

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.
反曲点科技创始人和首席执行官。
程序猿、设计师、奇怪的博主。
苹果死忠、热爱色彩斑斓的世界。
如有意向请随时 与我联系