On 24/02/2009, at 9:50 PM, Ashish Tiwari wrote:

I am trying to get finder icon view like behavior in my application. Using IKImageBrowserView I am able to show icons for contents of a directory but I also need file/directory name below those icons. For this I am trying to
insert NString into NSImage but text is now showing up in
IKImageBrowserView.


IKImageBrowserVIew has a much better way to handle this specific labelling requirement.

The objects it stores should implement the informal protocol for - imageTitle and -imageSubtitle, and the view will draw those strings below the icons for you.

Here are the methods I have in a simple custom object I use - I think I originally got this from one of Apple's samples though I'm afraid I forgot exactly which one. It simply provides the browser with the path to each image.

--Graham



// -------------------------------------------------------------------------
//  imageRepresentationType:
//
//  Set up the image browser to use a path representation.
// -------------------------------------------------------------------------
- (NSString*)   imageRepresentationType
{
        return IKImageBrowserPathRepresentationType;
}

// -------------------------------------------------------------------------
//  imageRepresentation:
//
//  Give the path representation to the image browser.
// -------------------------------------------------------------------------
- (id)          imageRepresentation
{
        return mPath;
}

// -------------------------------------------------------------------------
//  imageUID:
//
//  Use the absolute file path as the identifier.
// -------------------------------------------------------------------------
- (NSString*)   imageUID
{
    return mPath;
}


- (NSString*)   imageTitle
{
        return [[mPath lastPathComponent] stringByDeletingPathExtension];
}


- (NSString*)   imageSubtitle
{
        NSDictionary* attribs = [self imageAttributes];
        
        int w, h;
        
        w = [[attribs objectForKey:@"PixelWidth"] intValue];
        h = [[attribs objectForKey:@"PixelHeight"] intValue];
        
        return [NSString stringWithFormat:@"%d x %d", w, h];
}

_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to