NSTableView上的圆角 [英] Rounded corners on 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?
推荐答案
在NSTableView的子类中(或者你想要剪辑的任何视图/控件) )
In a subclass of NSTableView (or whatever view/control you want to clip)
- 覆盖
drawRect:
- 使用所需的形状创建NSBezierPath(可能
appendBezierPathWithRoundedRect:xRadius:yRadius:
只是记住使用视图的边界作为大小) - 发送路径
addClip
消息以将该形状添加到视图的剪切路径 - 调用super的
drawRect:
- Override
drawRect:
- Create an NSBezierPath with the shape you want (probably
appendBezierPathWithRoundedRect:xRadius:yRadius:
just remember to use the view's bounds as the size) - Send the path the
addClip
message to add that shape to the view's clipping path - Call super's
drawRect:
如果表视图有一个标题,你可能需要通过继承NSTableHeaderView。如果你有滚动条,你可能需要做同样的事情给他们,除了只剪辑某些角。希望你没有滚动条,因为我怀疑,看起来不错。
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.
如果你看看苹果公司的Welcome to Xcode窗口,你会发现,通过在顶部绘制自定义标题和在底部绘制一个文本块,使它们不必绕着表视图本身,就可以避开它。如果你能做我喜欢的事情。
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.
这篇关于NSTableView上的圆角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!