我正在尝试更改从 NIB 加载的窗口表中 NSTextField
的鼠标光标。
根据文档,我对 NSTextField
进行了子类化并实现了 resetCursorRects
.
- (void) resetCursorRects {
[self addCursorRect:[self bounds] cursor:[NSCursor pointingHandCursor]];
}
这从未被调用过。即使在 NSWindowViewController
中添加以下内容后也不会:
- (void) windowDidLoad {
[self.window invalidateCursorRectsForView:self.linkTextField];
}
我还通过在 NSTextField
子类中添加以下内容来尝试使用跟踪区域:
- (void) awakeFromNib {
NSTrackingArea* trackingArea = [[NSTrackingArea alloc] initWithRect:self.bounds
options:(NSTrackingCursorUpdate | NSTrackingActiveAlways)
owner:self
userInfo:nil];
[self addTrackingArea:trackingArea];
}
- (void)cursorUpdate:(NSEvent *)theEvent {
[[NSCursor pointingHandCursor] set];
}
也没有用。我做错了什么?
最佳答案
Clickable links with NSTextField
如上所述,我在子类化 NSTextField
后得到了这个工作:
- (void)resetCursorRects {
[self addCursorRect:[self bounds] cursor:[NSCursor pointingHandCursor]];
}
关于macos - 无法更改 NSTextField 的鼠标光标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12079531/