4

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

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
pierocampanelli
  • 960
  • 5
  • 19

1 Answers1

6

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.

Levi
  • 2,103
  • 14
  • 9
  • I suspect there might be a performance problem if the scrolling image browser contained hundreds of images. An alternative would be to use `visibleItemIndexes` to just add tool tips for the visible items, and refresh the tool tips when the view scrolls. – JWWalker Jan 16 '14 at 22:48