-->

Subclassing NSScroller, how to get rid of the whit

2019-04-11 01:29发布

问题:

I've created an iTunes like subclass of NSScroller, however if both the horizontal and vertical scrollers are visible in an NSScrollView or NSTableView I'm left with an ugly white square in the lower right corner. Anyone has a clue on where to add my custom drawing to fill that in with something prettier?

回答1:

Ok, I think I have the solution(s).

  • Either you tell the scrollview not to draw its background, in that case anything below it will fill the corner.

  • Or, which is what I did, you override the scrollview's drawRect method with the following:

    - (void)drawRect:(NSRect)rect{
       [super drawRect: rect];
    
       if([self hasVerticalScroller] && [self hasHorizontalScroller]){
         NSRect vframe = [[self verticalScroller]frame];
         NSRect hframe = [[self horizontalScroller]frame];
         NSRect corner;
         corner.origin.x = NSMaxX(hframe);
         corner.origin.y = NSMinY(hframe);
         corner.size.width = NSWidth(vframe);
         corner.size.height = NSHeight(hframe);
         // your custom drawing in the corner rect here
      }
    }