質問

NSCellをサブクラス化してカスタムの背景ハイライトを描画します。ドキュメンテーションは、オーバーライドhighlight:withFrame:inView:がこれを実行できるようにする必要があることを示唆しているようですが、この方法は呼び出されることはありません。

代わりに、drawInteriorWithFrame:inView:を上書きしました。これは細かく機能します - セルに欲しいものを描くことができます。しかし、問題は私自身のすべてを描く必要があるということです。

カスタム描画強調表示セル:

画像の記入ここで

しかし、私はバックグラウンド(ハイライト)を再描画し、拡張セルの主な機能を使用する機能を保持したいだけです。

画像の説明を入力します

私はもちろん、テキストを自分自身で描くだけできますが、私はこれをやることが簡単な方法があることを願っています。

あらゆる助けが大いに評価されています。

役に立ちましたか?

解決

Thanks to the help of @Bavarious I've managed to work it out. My extended NSTextFieldCell class implementation now contains:

-(NSColor *)highlightColorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
    return nil;
}

- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
    if ([self isHighlighted]) {
        // Draw highlight background here
    }

    [super drawInteriorWithFrame:cellFrame inView:controlView];
}

The key is to make sure you return nil for highlightColorWithFrame:inView: to stop drawInteriorWithFrame:inView: drawing a background and yet still calling it to draw the main content (in this case text).

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top