IKImageBrowserView, drawing on layers and retina display
IKImageBrowserView, drawing on layers and retina display
- Subject: IKImageBrowserView, drawing on layers and retina display
- From: Dragan Milić <email@hidden>
- Date: Mon, 10 Feb 2014 10:30:19 +0100
I'm trying to use IKImageBrowser class for something which is supposed to resemble Finder's icon view appearance. Hence, I need quite customized item titles, e.g. multiline string, oval gradient background (like Finder's label indicators), etc. Customizing item's title frame and views title (setting custom paragraph style with custom truncating etc.) didn't give any results, item titles remained single-lined. And besides, I would't be able to do anything about other graphics element, which are part of item's title in my case.
Therefore I took an approach to drive item titles myself in the item's cell background (IKImageBrowserCellBackgroundLayer) layer. I supplied a custom CALayer for that layer and implemented it's drawing delegate method. Here's how that code looks like:
- (CALayer *)layerForType:(NSString *)aType
{
if ([aType isEqualToString:IKImageBrowserCellBackgroundLayer])
{
CALayer *result = [CALayer layer];
[result setDelegate:self];
[result setFrame:[self frame]];
[result setName:aType];
[result setNeedsDisplay];
return result;
}
return [super layerForType:aType];
}
- (void)drawLayer:(CALayer *)aLayer inContext:(CGContextRef)aContext
{
if ([[aLayer name] isEqualToString:IKImageBrowserCellBackgroundLayer])
{
// Set the current context.
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:aContext flipped:[self imageBrowserView]]];
// Draw here...
[NSGraphicsContext restoreGraphicsState];
}
}
This works fine in general, but I'm facing two problems I can't find a way to solve:
1. All string drawing in the cell's background layer appear without antialiasing. Other drawing (Bezier Paths, images…) produce expected results.
2. All drawing in the cell's background layer in NOT retina-compliant! Not strings, not any other drawing.
I should note that I used standard NSImage, NSBezierPath and NSString drawing methods. Drawing exactly the same contents with the same code in a custom view produces expected results (antialiased strings, all fine on both non-retina and retina screens).
I haven't done many things with CALayers in the past, so maybe I'm missing some setting to make this work, but it doesn't look like that looking at that class' public API. On the other hand I find it hard to believe that IKImageBrowserView custom drawing onto its layers is not retina-compliant!
If necessary, I can provide sample snapshots of results on displays of both type.
Hopefully will someone know how to solve this. Thanks in advance.
-- Dragan
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden