NSTableView 上的圆角

发布于 2024-10-06 21:01:23 字数 140 浏览 0 评论 0原文

我有一个类似于 NSBox 的自定义视图子类,它绘制圆角框背景。问题是,如果我在框视图中放置像 NSTableView 这样的视图,它不会夹到圆角。有什么方法可以圆化 NSTableView 及其父滚动视图的角吗?

I have a custom view subclass similar to NSBox that draws a rounded box background. The problem is that if I place a view like an NSTableView in the box view, it does not clip to the rounded corners. Is there any way to round the corners of NSTableView and its parent scroll view?

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

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

发布评论

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

评论(1

鸠书 2024-10-13 21:01:23

我还没有尝试过使用表视图,但尝试过使用其他控件。

在 NSTableView 的子类(或您想要剪辑的任何视图/控件)中

  1. 覆盖 drawRect:
  2. 创建一个具有您想要的形状的 NSBezierPath (可能是 appendBezierPathWithRoundedRect:xRadius:yRadius: 只是记住使用视图的边界作为大小)
  3. 向路径发送addClip消息以将该形状添加到视图的剪切路径
  4. 调用super的drawRect:

如果表视图有标题您可能需要通过子类化 NSTableHeaderView 来修剪顶角。如果你有滚动条,你可能必须对它们做同样的事情,除了只剪掉某些角落。希望你没有滚动条,因为我怀疑这看起来是否正确。基本上,您想要剪切绘制该部分的视图/控件,剪切父视图不会导致子视图被剪切。

如果您查看 Apple 的“欢迎使用 Xcode”窗口,他们会通过在顶部绘制自定义标题并在底部绘制文本块来摆脱它,这样他们就不必将表格视图本身舍入。如果你能做这样的事情我会的。

I haven't tried this with a table view but have with other controls.

In a subclass of NSTableView (or whatever view/control you want to clip)

  1. Override drawRect:
  2. Create an NSBezierPath with the shape you want (probably appendBezierPathWithRoundedRect:xRadius:yRadius: just remember to use the view's bounds as the size)
  3. Send the path the addClip message to add that shape to the view's clipping path
  4. Call super's drawRect:

If the table view has a header you may need to clip the top corners by subclassing NSTableHeaderView. And if you have scrollbars you may have to do the same thing to them except only clip certain corners. Hopefully you don't have scrollbars because I doubt that would look right. Basically you want to clip the view/control that draws that part, clipping the parent will not cause subviews to be clipped.

If you look at Apple's Welcome to Xcode window they get away with it by drawing a custom header at the top and a text block at the bottom so they don't have to round the table view itself. If you can do something like that I would.

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