Cocoa: change cursor when it's over an NSButto

2019-01-11 18:10发布

How can I change the cursor when it's over an NSButton?

3条回答
不美不萌又怎样
2楼-- · 2019-01-11 18:57

You should subclass NSButton first, then add the code below.

- (void)resetCursorRects
{
    if (self.cursor) {
        [self addCursorRect:[self bounds] cursor: self.cursor];
    } else {
        [super resetCursorRects];
    }
}

Now you can set cursor as you like.

[self.button setCursor:[NSCursor pointingHandCursor]];

Note: add cursor as a property of your subclass, like this:

@property (strong) NSCursor *cursor;  
查看更多
地球回转人心会变
3楼-- · 2019-01-11 19:01
[yourButton addCursorRect:[yourButton bounds] cursor:[theCursorYouWant]];
查看更多
ゆ 、 Hurt°
4楼-- · 2019-01-11 19:13

Have the button add a cursor rect.

查看更多
登录 后发表回答