IKImageBrowserView: how to display tooltip for every item?

897 views Asked by At

I digged in documentation but didn't find how to do. How can I add tooltip for every item in IKImageBrowserView?

1

There are 1 answers

1
Levi On BEST ANSWER

The IKImageBrowserView is an NSView, so you can add the tooltip rectangles using these functions:

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSView_Class/Reference/NSView.html#//apple_ref/doc/uid/20000014-SW47

For my implementation, I have the image browser inside a scrollview that doesn't resize, so I only have to update the tool tips when my data changes using this code, where images is my datasource array:

[imageBrowser reloadData];
[imageBrowser removeAllToolTips];
for (int i=0; i<[images count]; i++) {
    NSRect rect = [imageBrowser itemFrameAtIndex:i];
    ImageObject *image = [images objectAtIndex:i];
    [imageBrowser addToolTipRect:rect owner:self userData:image];
}

Then I implemented this function:

- (NSString*)view:(NSView *)view stringForToolTip:(NSToolTipTag)tag point:(NSPoint)point userData:(void *)data {
    ImageObject *image = (ImageObject*)data;
    return [image imageTitle];
}

If your image browser changes its layout (you resize it adding/removing columns, or you change the zoom, etc) you will need to update all the tool tips.