0

カスタム NSTextFieldCell を作成し、- (void)drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView *)controlViewここで独自の描画を行うために上書きしました。ただ、背景の描画が苦手です。呼び出さないとsuper背景がクリアされず、その後の描画でにじみ効果のようなものが作成されます。drawsBackground が設定されている場合、これは発生しません。この場合、cellFrame を背景色で塗りつぶすことができるためです。

- (void)drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView *)controlView {
    if (self.drawsBackground) {
        [self.backgroundColor set];
    } else {
        [NSColor.clearColor set];
    }
    NSRectFill(cellFrame);

    [self.attributedStringValue drawInRect: cellFrame];
}

ここに画像の説明を入力

しかし、背景の描画が無効になっている場合、背景をクリアするにはどうすればよいですか? もちろん、テキストビューの下にある他のコンテンツが透けて見えるようにしたいです(したがって、スーパービューの背景色で消去するだけでは解決できません)。

4

1 に答える 1

2

セルを a[NSColor clearColor]で塗りつぶそうとすると、黒く描画されます。不要な場合は Fill を避けるようにしてください。また、通話を削除することができますsuper

例:

- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
    if (self.drawsBackground) {
        if (self.backgroundColor && self.backgroundColor.alphaComponent>0) {

            [self.backgroundColor set];
            NSRectFill(cellFrame);
        }
    }
    NSRect titleRect = [self titleRectForBounds:cellFrame];
    NSAttributedString *aTitle = [self attributedStringValue];
    if ([aTitle length] > 0) {
        [aTitle drawInRect:titleRect];
    }
}
于 2014-09-15T14:08:55.130 に答える