子类化NSScroller,如何去掉右下角的白色方块?

发布于 2024-08-17 07:22:46 字数 132 浏览 3 评论 0原文

我创建了一个类似 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我也只是我 2024-08-24 07:22:46

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

  • 要么你告诉滚动视图不要绘制它的背景,在这种情况下,它下面的任何东西都会填充角落。

    要么你告诉滚动视图不要绘制它的背景

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

    - (void)drawRect:(NSRect)rect{
       [超级绘制矩形:矩形];
    
       if([self hasVerticalScroller] && [self hasHorizo​​ntalScroller]){
         NSRect vframe = [[selfverticalScroller]frame];
         NSRect hframe = [[self Horizo​​ntalScroller]frame];
         NSRect 角点;
         角点.origin.x = NSMaxX(hframe);
         角点.origin.y = NSMinY(hframe);
         角.尺寸.宽度 = NSWidth(vframe);
         角.尺寸.高度 = NSHeight(hframe);
         // 您在此处的角矩形中自定义绘图
      }
    }
    

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
      }
    }
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文