How to customize a NSSlider

孤街醉人 提交于 2019-12-06 11:49:05
  1. I found a mistake in your calculation of the x position of the knob rectangle: You used the height of the image where you should have used the width.

  2. The cell drawing is being clipped to the frame of the control. Maybe you could expand the control frame when your cell awakes.

  3. You need to use the NSImage method drawInRect:fromRect:operation:fraction:respectFlipped:hints:, and pass YES for the respectFlipped: parameter. Apple's controls generally do use flipped coordinates.

Added: Expanding the frame in awakeFromNib doesn't seem to work, the frame gets set back. Here's something that does work. Instead of overriding drawBarInside:flipped:, add this override:

- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
    NSRect controlFrame = [controlView frame];
    float bgHeight = self.backgroundImage.size.height;
    if (controlFrame.size.height < bgHeight)
    {
        controlFrame.size.height = bgHeight;
        [controlView setFrame: controlFrame];
    }

    [self.backgroundImage
        drawInRect: [controlView bounds]
        fromRect: NSZeroRect
        operation: NSCompositeSourceOver
        fraction: 1.0
        respectFlipped: YES
        hints: NULL];
    [self drawKnob];
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!