NSOutlineView 控制高亮和缩进

发布于 2024-10-16 17:30:43 字数 1111 浏览 4 评论 0原文

在我的大纲视图中,我使用的是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

dawn曙光 2024-10-23 17:30:43

突出显示由 NSOutlineView 处理(实际上,它是从 NSTableView 继承的行为)。无论如何,您不应该关注单元格,而应该查看子类化 NSOutlineView 并覆盖 highlightSelectionInClipRect:。这就是您应该进行自定义突出显示绘图的地方。

The highlighting is handled by the NSOutlineView (well, actually, it's inherited behavior from NSTableView). Anyway, instead of focusing on the cell, you should take a look at subclassing NSOutlineView and overriding highlightSelectionInClipRect:. That's where you should do your custom highlight drawing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文