1

我创建了一个 NSPopUpButtonCell 子类来自定义它的外观。

当从弹出窗口中选择其中一个菜单项时,它会以 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 上的边框属性。

如果边界实际上已关闭,则必须将其打开并关闭。

更好的方法是使用 - (void)drawBorderAndBackgroundWithFrame:(NSRect)cellFrame inView:(NSView *)controlView

于 2015-10-14T06:42:52.990 回答