继承NSScroller,如何去掉右下角的白色方块? [英] Subclassing NSScroller, how to get rid of the white square in the lower right corner?

查看:16
本文介绍了继承NSScroller,如何去掉右下角的白色方块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个类似于 iTunes 的 NSScroller 子类,但是如果水平和垂直滚动条在 NSScrollView 或 NSTableView 中都可见,我会在右下角留下一个难看的白色方块.任何人都知道在哪里添加我的自定义绘图以用更漂亮的东西填充它?

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?

推荐答案

好的,我想我有解决方案.

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.

或者,这就是我所做的,您使用以下内容覆盖滚动视图的 drawRect 方法:

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

这篇关于继承NSScroller,如何去掉右下角的白色方块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆