NSOutlineView Changing disclosure Image

前端 未结 5 2172
青春惊慌失措
青春惊慌失措 2020-12-30 16:56

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/0

5条回答
  •  失恋的感觉
    2020-12-30 17:36

    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];
    }
    

    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.

提交回复
热议问题