1

外観をカスタマイズする NSPopUpButtonCell サブクラスを作成しました。

メニュー項目の 1 つがポップアップから選択されると、OS X 10.10 の標準的なポップアップの外観で選択がアニメーション化されます。

カスタムの外観でアニメーション化したいと思います。

カスタマイズされたポップアップ

カスタマイズされたポップアップ

選択範囲のアニメーション

選択範囲のアニメーション

私の実装

- (void)drawBezelWithFrame:(NSRect)frame inView:(NSView *)controlView {

    [[NSGraphicsContext currentContext] saveGraphicsState];

    NSBezierPath *rectanglePath = [NSBezierPath bezierPathWithRoundedRect:frame xRadius:5.0 yRadius:5.0];
    [[NSColor colorWithWhite:0.7 alpha:1.0] setFill];
    [rectanglePath fill];

    float width = frame.size.width;
    float height = frame.size.height;

    NSBezierPath *path = [NSBezierPath bezierPath];

    [path moveToPoint:CGPointMake(width - 5, height/2 - 2)];
    [path lineToPoint:CGPointMake(width - 10, height/2 - 7)];
    [path lineToPoint:CGPointMake(width - 15, height/2 - 2)];


    [path moveToPoint:CGPointMake(width - 5, height/2 + 2)];
    [path lineToPoint:CGPointMake(width - 10, height/2 + 7)];
    [path lineToPoint:CGPointMake(width - 15, height/2 + 2)];

    [path setLineWidth:2.0];

    [[NSColor darkGrayColor] setStroke];
    [path stroke];

    [NSGraphicsContext restoreGraphicsState];
}
4

1 に答える 1

1

Interface Builder で枠付きプロパティをオフにする必要があります。

bordered が実際にオフになっている場合は、オンにしてからオフにする必要があります。

より良い方法は使用です - (void)drawBorderAndBackgroundWithFrame:(NSRect)cellFrame inView:(NSView *)controlView

于 2015-10-14T06:42:52.990 に答える