开发者

Rounded corners on NSTableView

I have a custom view subclass similar to NSBox that draws a rounded box background. The problem 开发者_JAVA技巧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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜