Subclassing NSScroller, how to get rid of the white square in the lower right corner?

旧时模样 提交于 2020-01-01 15:57:53

问题


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
      }
    }
    


来源:https://stackoverflow.com/questions/2024545/subclassing-nsscroller-how-to-get-rid-of-the-white-square-in-the-lower-right-co

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!