NSOutlineView更改公开图像 [英] NSOutlineView Changing disclosure Image

查看:325
本文介绍了NSOutlineView更改公开图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的大纲视图,我添加了自定义单元格,要绘制自定义单元格,我指的是示例代码,在Cocoa文档中出现

I my outline view, i am adding Custom cell, To drawing custom cell, i am referring example code , present in the Cocoa documentation

http://www.martinkahr.com/2007/05/04/nscell -image-and-text-sample /

我想用我的自定义图片更改单元格的公开图片,我试过以下事情

I want to change the disclosure image of the cell with my custom image, i have tried following things

- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item 
    {
        if([item isKindOfClass:[NSValue class]])
        {
            MyData *pDt = (MyData *)[item pointerValue];
            if(pDt->isGroupElement())
            {
                [cell setImage:pGroupImage];
            }
        }
}

有没有其他方法来更改公开图片,
也如何在willDisplayCell中找出是否展开或折叠,因此我可以相应地设置图像,

but that too not working, Is there any other way to change the disclosure image, also how can i find out in willDisplayCell whether Item is expand or collapse, so i can set the image accordingly,

这只是更改披露图片的地方吗?

Is this only the place to change the disclosure image ?

推荐答案

你有基本的想法,但你需要做的是自己绘制图像。这里是我使用的代码:

You've got the basic idea but what you will need to do is draw the image yourself. Here's the code I use:

- (void)outlineView:(NSOutlineView *)outlineView willDisplayOutlineCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item {
    NSString *theImageName;
    NSInteger theCellValue = [cell integerValue];
    if (theCellValue==1) {
        theImageName = @"PMOutlineCellOn";
    } else if (theCellValue==0) {
        theImageName = @"PMOutlineCellOff";
    } else {
        theImageName = @"PMOutlineCellMixed";
    }

    NSImage *theImage = [NSImage imageNamed: theImageName];
    NSRect theFrame = [outlineView frameOfOutlineCellAtRow:[outlineView rowForItem: item]];
    theFrame.origin.y = theFrame.origin.y +17;
    // adjust theFrame here to position your image
    [theImage compositeToPoint: theFrame.origin operation:NSCompositeSourceOver];
    [cell setImagePosition: NSNoImage];
}

您将需要3张不同的图片, c $ c> ON 状态,一个用于 OFF 状态,还有一个用于 MIXED 状态,它应该在两者之间的中间。混合状态确保您仍然可以获得开始和关闭动画。

You will need 3 different images as you can see, one for the ON state, one for the OFF state and also one for the MIXED state which should be halfway between the two. The mixed state makes sure you still get the opening and closing animation.

这篇关于NSOutlineView更改公开图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆