添加透明背景的行
我有一个 NSTableView,下面有一个“添加”按钮。当我单击该按钮时,一个新行将添加到表中并准备好供用户输入。
该行显示为白色。我可以将行的颜色设置为透明颜色吗?这可能吗?我不知道该怎么做。
我将表格设置为透明的代码:
[myTable setBackgroundColor:[NSColor clearColor]];
[[myTable enclosingScrollView] setDrawsBackground: NO];
添加行的代码:
[myTableArray addObject:@""];
[myTable reloadData];
[myTable editColumn:0 row:[myTableArray count]-1 withEvent:nil select:YES];
I have an NSTableView, with an "add" button below it. When I click on the button, a new row gets added to the table and is ready for user input.
The row appears in a white color. Can I set the color of the row to a transparent color? Is this possible? I cannot figure out how to do this.
My code for setting my table to be transparent:
[myTable setBackgroundColor:[NSColor clearColor]];
[[myTable enclosingScrollView] setDrawsBackground: NO];
Code for adding a row:
[myTableArray addObject:@""];
[myTable reloadData];
[myTable editColumn:0 row:[myTableArray count]-1 withEvent:nil select:YES];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将单元格的背景颜色设置为透明
[cell setBackgroundColor:[UIColor clearColor]];
这对我有用
try setting the cell's background color transparent
[cell setBackgroundColor:[UIColor clearColor]];
it works for me
我认为您可能需要进行一些子类化才能完成您想要做的事情。
通过子类化您的 NSTableView,您可以重写 preparedCellAtColumn:row: 方法,如下所示:
但是,NSTableView 文档表明您的单元格调用了另一个方法,该方法似乎会重置颜色。 (editWithFrame:inView:editor:delegate:event:) 创建覆盖此方法的 NSTextViewCell 子类可能会满足您的要求。
编辑
搜索文档我发现了这个:
因此,在这种情况下,您需要自定义的是字段编辑器,它会覆盖您在 NSTableView 或单元格上执行的任何显示更改。
字段编辑器由窗口委托的方法 windowWillReturnFieldEditor:toObject 返回:
这应该允许您在将编辑的单元格返回到 NSTableView
EDIT 之前设置其属性
尝试此方法无济于事,但可能会有所帮助:
I think you may have to do some subclassing to accomplish what you're trying to do.
By subclassing your NSTableView you can override the preparedCellAtColumn:row: method like so:
However, the NSTableView documentation indicates that your cell has another method called, which seems to reset the color. (editWithFrame:inView:editor:delegate:event:) Creating a subclass of NSTextViewCell that overrides this method may do what you're looking for.
EDIT
Searching through the documentation I found this:
So what you need to customize in this case is the field editor, which is covering up any display changes you're performing on the NSTableView or the cell.
The field editor is returned by the window delegate's method windowWillReturnFieldEditor:toObject:
This should let you set the properties of the edited cell before returning it to the NSTableView
EDIT
Tried this to no avail but might help out: