如何判断 NSTextFieldCell isHighlighted 何时没有焦点?
我已经对 NSTextFieldCell (在 NSTableView 内)进行了子类化,以在选择单元格(即行)时绘制自定义前景色(例如 isHighlighted 为 true)并且一切正常。
问题是当表视图失去焦点时我想用不同的颜色绘制选定的行,如何确定包含单元格的表视图是否不是 drawWithFrame:(NSRect)cellFrame inView:(NSView 内的第一响应者*)控制视图?
我当前的代码是
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
NSColor* textColor = [self isHighlighted]
? [NSColor alternateSelectedControlTextColor]
: [NSColor darkGrayColor];
}
I've subclassed a NSTextFieldCell (inside a NSTableView) to draw a custom foreground color when a cell (ie row) is selected (eg isHighlighted is true) and everything works fine.
The problem is when the table view loses the focus I want to draw the selected rows with a different color, how can I determine if the table view containing the cell isn't the first responder inside drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView?
My current code is
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
NSColor* textColor = [self isHighlighted]
? [NSColor alternateSelectedControlTextColor]
: [NSColor darkGrayColor];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我找到了一个使用firstResponder的解决方案,它很简单而且看起来很高效
I've found a solution that uses the firstResponder, it is simple and seems efficient
还有一件事,上面的代码是完美的,但是如果你有多个窗口
你需要检查你的窗户是否是关键
one more thing, the above code is perfect, however if you have multiple windows
you will need to check if your window is key
我发现最好的方法不会让您处理响应者(因为有时
controlView
的超级视图是响应者或一些废话)是使用编辑器:就这么简单!
The best way I've found that doesn't make you deal with responders (since sometimes the
controlView
's superview is the responder or some nonsense) is to use the editor:Easy as that!