In my application I have taken a table view and displaying some NSString objects within it. User can also edit any row within it.
When I do not change color of NSTextFieldCell in NSTableColumn in IB, it shows default display property of table view ie. when a row is selected, text of selected row starts appearing white, but when I change it to some other color, say blue, then it starts appearing like this:
To resolve this problem I tried to set text color of cell in selected row as white in table delegate method: tableView:willDisplayCell:forTableColumn:row:, but it caused another problem- text remained white when edited, thus it became difficult for user to identify text entered:
Can anyone suggest me some suitable solution to resolve it?
Thanks,
Miraaj
Test whether the cell is highlighted. If it is, set its text color to [NSColor alternateSelectedControlTextColor]. If not, set it to blue (or [NSColor controlTextColor] for the regular text color).
Related
Which NSColor should I use for the text of a selected item in a NSTableView? I have my text field inside a stack view, so the color doesn't get set automatically for selected rows. I tried using NSColor.selectedTextColor, but that's still black in 10.13/light mode. For the moment I'm using NSColor.windowBackgroundColor but that's not going to work in dark mode, where selected rows change the background color but not the text color.
NSColor.h in the 10.14 SDK shows this as alternateSelectedControlTextColor:
#property (class, strong, readonly) NSColor *alternateSelectedControlTextColor;
/* Foreground color inside emphasized and selected content: table views rows,
collection views, etc. Equivalent to +labelColor in a NSBackgroundStyleEmphasized
context.*/
The latter note was also mentioned in the Advanced Dark Mode wwdc talk:
https://developer.apple.com/videos/play/wwdc2018/218/?time=2161
Where on 10.14 the main label colors will just automatically switch to have the right look inside that selection.
I have NSCollectionView with custom items which contain NSTextField and NSImageView.
I realized highlight behavior of collection view items manually (ie. redefined the setSelected: method in my NSCollectionViewItem descendant class).
I successfully change the background color of selected items, but I miss one small but important thing: the text color of the selected item doesn't change.
I know that the NSTableView item highlighting changes the text color along with the background color, but I cannot mimic it since I don't know the algorithm of color's change.
The text color of my NSCollectionViewItems can be different. When I highlight the item in NSTableView, the gray text becomes lightgray, black becomes white and so on.
Does anybody know how they do that? Maybe there's a ready solution in the Cocoa API that I missed? Please help.
I am using a custom editor when editing the contents of a cell inside a Table view. From the docs I see that the custom editor has to be an NSTextView. So I put the text view in the document view, then I referenced it from the cell subclass through an IBOutlet in order to assign it as custom editor.
When doing all this, I can set the editor not to draw its background, but a thick white border is shown when the user edits that cell, and there is no way to remove it.
So I create the NSTextView programmatically, assigned it as the custom editor, and no white border is shown, but I can't change the background now, set it to clearColor, set the font, fontColor etc. I can't do anything with it. It is just a square with dark background and white text.
Is there something I am not doing? This is a bad approach?
Thank you.
The border is drawn by drawRect:, but I still don't know how to fix it by overriding drawRect:...
You may have a look at this link: http://www.cocoabuilder.com/archive/cocoa/129091-solved-re-disabling-nstableview-big-black-editing-box.html#129259
To start, there's an NSArrayController ("Servers") whose content is an array of "server" objects.
I also have an NSTableView with a column. The column is bound to Server's "arrangedObjects.status" property.
I use a custom NSValueConverter to make that status into an image for the column's dataCell which is an NSImageCell.
What I don't understand is why the images that show up in the column are correct, but consistently faded out. Just to test, I have the same image outside the table view for comparison and it draws fine. The colors in the images are not semi-transparent.
Does the NSImageCell draw the images as faded? Is there something I can configure in IB that will draw them fully saturated?
From Jim Correia on Cocoa-Dev:
"On 10.6, NSImageView will draw its content as dimmed when the control is disabled.
Your binding has “Conditionally Sets Enabled” turned on."
You might have the image view cell or column's "enabled" property set to NO (or unchecked in IB). I believe this fades the displayed image.
I've got an column of cells in an NSTableView that get their text color from the app's preference plist. I want to set the text color to white when highlighted, but have been unable to figure out a good way to do this.
Anybody got any ideas?
Assuming there's no easier way to do this, implement the tableView:willDisplayCell:forTableColumn:row: delegate method to set the cell's textColor to either [NSColor alternateSelectedControlTextColor] or [NSColor selectedControlTextColor] depending on whether rowIndex is in the table view's selectedRowIndexes set.
(The “selected” in “{alternateS,s}electedControlTextColor” refers to the control, not the text. You're using the alternate (or not alternate) text color for the selected control, which is the table view.)