【发布时间】:2012-02-18 22:55:37
【问题描述】:
我正在尝试创建一个带有圆角的 NSTableView(很像 iOS 的 Grouped 表格视图样式)。
然而,事实证明这是非常困难的。
我尝试过使用CALayers:
// ...
self.wantsLayer = YES;
self.layer.masksToBounds = YES;
self.layer.cornerRadius = 10.0;
// ...
适用于NSView 子类,但不适用于NSTableView 或NSScrollView。
我也尝试过覆盖 drawRect:,并使用 bezierPaths。
NSBezierPath *rectPath = [NSBezierPath bezierPathWithRect: self.bounds];
[rectPath appendBezierPathWithRoundedRect: self.bounds xRadius: 10 yRadius: 10];
[rectPath addClip];
[super drawRect: rectPath.bounds];
我没有在NSViews 上测试过这个方法,但它对NSTableViews 不起作用。
我之前在 StackOverflow 上看到过一些“重复”的问题,但是他们无法提供令人满意的解决方案。
Rounded corners on NSTableView 有 1 个“正确”答案,似乎只是因为提问者改变了目标而被标记。这个问题提示我尝试NSBezierPaths,但正如我所说,我似乎无法让该方法发挥作用。
NSTableView rounded corners 建议子类化一个 NSScrollView,但是这同样对 CALayers 没有响应。
任何建议将不胜感激。我想得到一个明确的答案,不仅是为了我自己,也是为了后代。
【问题讨论】:
标签: objective-c cocoa calayer nstableview nsbezierpath