Rounded corners on NSTableView

前端 未结 1 1316
抹茶落季
抹茶落季 2021-01-16 06:13

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 th

相关标签:
1条回答
  • 2021-01-16 07:05

    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 讨论(0)
提交回复
热议问题