0
votes

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 NSViews, but it does not work as-is for NSTableViews.

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 NSBezierPaths, 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.

1

1 Answers

2
votes

I also face the same problem of making round corner, but didnt got the answer.

Finally i did it in another way,I have make the Background of table transparent and added the image of .png files of round corner of 4pixel(that i want to show) just behind the table view .

In this way i have shown the table with round corner. Hope this solution works for you.