簡単にはありませんが、私は恐れています。あなたができる方法の1つは、imageTitle
を空白にして、描画テキストをCALayer
に残すことです。私はそれはかなりまともな結果を動作させることができました:

まず最初に、物事 - あなたは標準imageTitle
プロパティを使用するつもりはないから、あなたはあなたの中に新しいタイトルのプロパティを作成するには<IKImageBrowserItem>
-適合するデータオブジェクト。私は単に私に電話しましたtitle
。
次に、サブクラスIKImageBrowserCell
を作成します。カスタムセルを使用していることをIKImageBrowserView
に伝えてください。私はこのための迅速なカテゴリを書いた:
@implementation IKImageBrowserView(CustomCell)
- (IKImageBrowserCell *)newCellForRepresentedItem:(id)cell
{
return [[MyCustomImageBrowserCell alloc] init];
}
@end
次に、カスタムセルでは、方法- (CALayer *)layerForType:(NSString *)type
をオーバーライドします。
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context
{
// Set the current context.
[NSGraphicsContext saveGraphicsState];
NSGraphicsContext *nscg = [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO];
[NSGraphicsContext setCurrentContext:nscg];
NSString *title = [self.representedItem title];
// Wrap and center the text
NSMutableParagraphStyle *paragraphStyle = [[[NSMutableParagraphStyle alloc] init] autorelease];
[paragraphStyle setLineBreakMode:NSLineBreakByWordWrapping];
[paragraphStyle setAlignment:NSCenterTextAlignment];
NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
[attrs setObject:paragraphStyle forKey:NSParagraphStyleAttributeName];
[attrs setObject:[NSFont systemFontOfSize:12.0f] forKey:NSFontAttributeName];
CGFloat padding = 4.0f;
[title drawInRect:NSMakeRect(
0,
-(self.imageFrame.size.height + padding),
self.frame.size.width,
100
) withAttributes:attrs];
[NSGraphicsContext restoreGraphicsState];
}
残念ながら、このアプローチは、いくつかを持っていない:レイヤーの描画を処理するためにカスタムセルで-drawLayer:inContext:
メソッドを実装し、その後
- (CALayer *)layerForType:(NSString *)type
{
if([type isEqualToString:IKImageBrowserCellBackgroundLayer])
{
CALayer *layer = [CALayer layer];
layer.delegate = self;
layer.frame = self.frame; // the cell's frame
layer.name = type; // a way to refer to the layer location type during drawing if need be
[layer setNeedsDisplay];
return layer;
}
return [super layerForType:type];
}
:作成し、特定の層の場所の種類のためのCALayerを返します欠点。テキストには、imageTitle
のような青い選択の背景がありません。ただし、IKImageBrowserCellSelectionLayer
のカスタムCALayer内にNSBezierPath
を使用して、独自の選択背景を描画することはできます。
これで十分です。
ありがとうございます。私は実際にCATextLayerを使って本質的にあなたが提案したものをやってしまった。 (私たちはすでに、IKImageBrowserCellSelectionLayerをカスタマイズしてフレーム全体に枠線を描いて選択を指示していたので、そこに問題はありませんでした) –
ありがとうございました。私は - (NSRect)imageContainerFrameを追加しなければならなかった。 と数字で少し遊ぶが、これは動作します。しかし、アンチエイリアスはありません。 –
これは、IKImageBrowserViewのカスタム描画セルのための非常に小さなチュートリアルです。ありがとうございます! – zpasternack