透明 NSTableView

发布于 2024-10-12 23:41:02 字数 484 浏览 7 评论 0原文

我想自定义我的 NSTableView。我的总体要求是这样的:

  • 每一行有一张图片和一些文字;图像和文本可能不同。
  • 有些细胞可能没有图像。
  • 行高取决于一些外部因素。
  • 单元格不应该绘制背景,它应该显示 NSTableView 背景。

到目前为止,我可以用一些文本绘制透明单元格。我用谷歌搜索并发现我需要自定义每个单元格。现在我有这个问题:我应该保留两列,还是应该保留一列,在左侧放置一张图像,并在其旁边放置文本?

我还知道我需要重写两种方法:

- (void) drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView

因此,对于每个单元格,我需要绘制/构造单元格 - 谁能指导我?我的方向正确吗?我可以通过上述方法实现具有动态高度的透明背景吗?

I want to customize my NSTableView. My overall requirements are like this:

  • Each row will have one image and some text; images and text could be different.
  • Some cells might not have an image.
  • Row height is dependent upon some external factor.
  • A cell shouldn't draw the background, it should show the NSTableView background.

So far I am able to draw transparent cells with some text. I Googled and found out I need to customize each cell. Now I have this question: should I maintain two columns or should one column be okay, having one image on the left hand side and text adjacent to that?

I also understand that I need to override two methods:

- (void) drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView

So for each cell, I need to draw/construct the cell -- can anyone guide me? Am I going in the right direction? Can I achieve a transparent background with dynamic height with the above approach?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不醒的梦 2024-10-19 23:41:02

每一行都有一个图像和一些文本,

因此,有两列 - 一列包含图像单元格,另一列包含文本字段单元格。

图像和文字可能不同,

我希望如此。

某些单元格可能没有图像,

这不是问题。

行高取决于一些外部因素,

作为表视图的代表,它会询问您行的高度应该是多少。

单元格不应绘制背景,

除非您设置它,否则它不会绘制背景。

总体上应该显示 NSTableView 背景,

无论如何,表视图都会绘制自己的背景,您可以在 IB 的检查器中设置。如果您希望表视图不绘制背景,则可以将其背景颜色设置为透明颜色。

您不需要为此使用自定义单元格。

Each row will have one image and some text,

So, two columns—one with an image cell, the other with a text field cell.

images and text could be different,

I should hope so.

Some cell might not have the Image,

Not a problem.

Row height is depend upon some external factor,

Be the table view's delegate, and it will ask you what the row's height should be.

Cell shouldn't draw the background,

It won't unless you set it to do so.

it should overall it should show the NSTableView background,

The table view will draw its own background anyway, which you can set in IB's Inspector. If you wanted the table view to not draw a background, you would set its background colors to the clear color.

You don't need a custom cell for any of this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文