NSOutlineView 控制高亮和缩进
在我的大纲视图中,我使用的是 CustomCell,它只不过是从 Cocoa ImageTextCellRefrenceCode 中获取代码并进行了一些修改,
是否可以更改单元格的突出显示颜色?
到目前为止我已经做了以下工作, - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
if([self isHighlighted]){
NSColor *evenColor = [NSColor colorWithCalibratedRed:.1 green:0.1 blue: 0.1
alpha:1.0];
[evenColor set];
NSRectFill(cellFrame);
bSelected = YES;
}
}
这是有效的,但是发生了什么,我可以看到,突出显示单元格颜色首先从系统默认颜色开始,然后,它将被 EvenColor 覆盖, 我觉得问题是 cellFrame.origin.x,它不是从 0 开始,
应用这段代码后的输出如下
----- My Custom Cell ----------------
======================================
| blue | |
| color| even Color |
| | |
======================================
以及我所期望的
----- My Custom Cell ----------------
======================================
| |
| even Color |
| |
======================================
In my Outline view, i am using CustomCell, which is nothing but took the code from Cocoa ImageTextCell RefrenceCode with some modification,
Is it possible to change the highlight color for a cell ?
So far i have done following,
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
if([self isHighlighted]){
NSColor *evenColor = [NSColor colorWithCalibratedRed:.1 green:0.1 blue: 0.1
alpha:1.0];
[evenColor set];
NSRectFill(cellFrame);
bSelected = YES;
}
}
This is working but what is happening, i could see, hightlight cell color first start from system default color, then, it will get override by evenColor,
I feel the problem is cellFrame.origin.x, its not starting from 0,
output was as below after applying this piece of code
----- My Custom Cell ----------------
======================================
| blue | |
| color| even Color |
| | |
======================================
and what i was expecting
----- My Custom Cell ----------------
======================================
| |
| even Color |
| |
======================================
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
突出显示由 NSOutlineView 处理(实际上,它是从 NSTableView 继承的行为)。无论如何,您不应该关注单元格,而应该查看子类化
NSOutlineView
并覆盖highlightSelectionInClipRect:
。这就是您应该进行自定义突出显示绘图的地方。The highlighting is handled by the
NSOutlineView
(well, actually, it's inherited behavior fromNSTableView
). Anyway, instead of focusing on the cell, you should take a look at subclassingNSOutlineView
and overridinghighlightSelectionInClipRect:
. That's where you should do your custom highlight drawing.