Adding a line with a transparent background

I have an NSTableView with an add button below it. When I click on the button, a new row is added to the table and is ready for user input.

The string is displayed in white. Can a line color be set to a transparent color? Is it possible? I can’t figure out how to do this.

My code for adjusting the transparency of my table:

[myTable setBackgroundColor:[NSColor clearColor]]; [[myTable enclosingScrollView] setDrawsBackground: NO]; 

Code to add a line:

 [myTableArray addObject:@""]; [myTable reloadData]; [myTable editColumn:0 row:[myTableArray count]-1 withEvent:nil select:YES]; 
+4
source share
2 answers

try setting the background color of the cell to transparent

[cell setBackgroundColor: [UIColor clearColor]];

he works for me

+1
source

I think you might have to do some subclasses to accomplish what you are trying to do.

By subclassing your NSTableView, you can override the prepareCellAtColumn: row: method:

 - (NSCell*) preparedCellAtColumn:(NSInteger)column row:(NSInteger)row { NSTextFieldCell *edit_field; edit_field = (NSTextFieldCell*) [super preparedCellAtColumn:column row:row]; if ( [self editedRow] == row && [self editedColumn] == column ) { [edit_field setBackgroundColor:[NSColor clearColor]]; [edit_field setDrawsBackground:NO]; } return edit_field; } 

However, the NSTableView documentation indicates that another method is being called in your cell, which appears to match the reset color. (editWithFrame: inView: editor: delegate: event :) Creating a subclass of NSTextViewCell that overrides this method can do what you are looking for.

EDIT Documentation search I found this:

If the receiver is not an NSCell text object, editing is not performed. Otherwise, the field editor (textObj) is up to aRect and its supervisor is set to controlView, so it covers the receiver exactly.

So in this case, you need to set up a field editor that hides any display changes that you make in the NSTableView or cell.

The field editor is returned using the delegate method windowWillReturnFieldEditor: toObject:

This will allow you to set the properties of the edited cell before returning it to NSTableView

EDIT Tried this to no avail, but could help:

 -(id) windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)client{ NSText *editor = [window fieldEditor:YES forObject:client]; [editor setBackgroundColor:[NSColor clearColor]]; [editor setDrawsBackground:NO]; return [editor autorelease]; } 
0
source

Source: https://habr.com/ru/post/1340764/


All Articles