透明 NSTableView
我想自定义我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,有两列 - 一列包含图像单元格,另一列包含文本字段单元格。
我希望如此。
这不是问题。
作为表视图的代表,它会询问您行的高度应该是多少。
除非您设置它,否则它不会绘制背景。
无论如何,表视图都会绘制自己的背景,您可以在 IB 的检查器中设置。如果您希望表视图不绘制背景,则可以将其背景颜色设置为透明颜色。
您不需要为此使用自定义单元格。
So, two columns—one with an image cell, the other with a text field cell.
I should hope so.
Not a problem.
Be the table view's delegate, and it will ask you what the row's height should be.
It won't unless you set it to do so.
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.