I'm attempting to create an NSTableView with rounded corners (much like iOS's Grouped
style of table view).
However, this is proving to be exceptionally difficult.
I've tried to use CALayers
:
// ...
self.wantsLayer = YES;
self.layer.masksToBounds = YES;
self.layer.cornerRadius = 10.0;
// ...
which works for NSView
subclasses, but not NSTableView
or NSScrollView
.
I've also tried to override drawRect:
, and use bezierPaths.
NSBezierPath *rectPath = [NSBezierPath bezierPathWithRect: self.bounds];
[rectPath appendBezierPathWithRoundedRect: self.bounds xRadius: 10 yRadius: 10];
[rectPath addClip];
[super drawRect: rectPath.bounds];
I've not tested this method on NSView
s, but it does not work as-is for NSTableView
s.
I've seen a few "duplicate" questions here on StackOverflow before, however they have not been able to provide satisfactory solutions.
Rounded corners on NSTableView has 1 "correct" answer, seemingly marked so simply because the asker changed his objective. This question gave me the prompting to try NSBezierPath
s, but as I've said, I can't seem to get that method working.
NSTableView rounded corners suggests subclassing an NSScrollView, however that was equally unresponsive to CALayers
.
Any suggestions would be greatly appreciated. I'd like to get clear-cut an answer not just for myself but for posterity.