문제

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

도움이 되었습니까?

해결책

[yourButton addCursorRect:[yourButton bounds] cursor:[theCursorYouWant]];

다른 팁

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;  

Following the already given example, creating a subclass of NSButton in Swift 5:

import AppKit

class Button: NSButton {
    override func resetCursorRects() {
        addCursorRect(bounds, cursor: .pointingHand)
    }
}

Have the button add a cursor rect.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top