NSTableView 上的圆角
我有一个类似于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还没有尝试过使用表视图,但尝试过使用其他控件。
在 NSTableView 的子类(或您想要剪辑的任何视图/控件)中
drawRect:
appendBezierPathWithRoundedRect:xRadius:yRadius:
只是记住使用视图的边界作为大小)addClip
消息以将该形状添加到视图的剪切路径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)
drawRect:
appendBezierPathWithRoundedRect:xRadius:yRadius:
just remember to use the view's bounds as the size)addClip
message to add that shape to the view's clipping pathdrawRect:
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.