gpt4 book ai didi

Cocoa:用圆底角屏蔽 NSTableView

转载 作者:行者123 更新时间:2023-12-03 16:31:31 26 4
gpt4 key购买 nike

我正在尝试找出如何用底部圆角掩盖 NSTableView - 但仅在底部。

在此图像中,未应用任何效果:

The bottom corners are square

在这些图像中,您可以看到圆角,我对角使用了以下代码:

self.scrollView.wantsLayer = TRUE;
self.scrollView.layer.cornerRadius = 6;

top corners and bottom corners rounded

我不知道如何消除左上角和右上角的圆角:

corners are rounded

我尝试了几种不同的选项,但均无济于事:

//creating a path
//this is a category from github.com/iccir/XUIKit
NSBezierPath * path = [NSBezierPath bezierPathWithRoundedRect:self.tableView.bounds byRoundingCorners:XUIRectCornerBottomLeft|XUIRectCornerBottomRight cornerRadii:CGSizeMake(6, 6)];
CAShapeLayer * layer = [CAShapeLayer layer];
layer.fillColor = [[NSColor blackColor] CGColor];
layer.path = [path CGPath];

//attempt 1
self.scrollView.contentView.wantsLayer = TRUE;
self.scrollView.contentView.layer.mask = layer;
self.scrollView.contentView.layer.masksToBounds = TRUE;

//attempt 2
((NSView*)self.scrollView.documentView).wantsLayer = TRUE;
((NSView*)self.scrollView.documentView).layer.mask = layer;
((NSView*)self.scrollView.documentView).layer.masksToBounds = TRUE;

//attempt 3
self.scrollView.wantsLayer = TRUE;
self.scrollView.layer.mask = layer;
self.scrollView.layer.masksToBounds = TRUE;

最终发生的事情是一切都消失了:

table view content is gone

有人知道如何正确处理这个问题吗?谢谢!

最佳答案

我明白了。此代码有效:

//creating a path
//github.com/iccir/XUIKit
NSBezierPath * path = [NSBezierPath bezierPathWithRoundedRect:CGRectMake(0,0,325,80) byRoundingCorners:XUIRectCornerBottomLeft|XUIRectCornerBottomRight cornerRadii:CGSizeMake(6, 6)];
CAShapeLayer * layer = [CAShapeLayer layer];
layer.path = [path CGPath];
self.scrollView.wantsLayer = TRUE;
self.scrollView.layer.mask = layer;

我的问题是我最初创建的路径的 .height 为 0。

另请注意,如果 TableView 更改大小,图层蒙版也必须更改。

关于Cocoa:用圆底角屏蔽 NSTableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24336974/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com