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.)
Related
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'm making an Cocoa app for Yosemite.
I added a view based NSTableView in Interface builder, but the border 2 pixel width and thicker than Yosemite's Finder's.
And the cell selection color is blue, while Yosemite's Finder's is gray.
And this is how Yosemite's Finder's table view looks like.
I checked the settings in Interface Builder.
The super scroll view of NSTableView's frame setting is (0,0,149,257):
While the Clip View's frame setting is (1, 1, 147, 255) and can not be changed.
And how to make a same NSTableView as Yosemite's Finder's?
Thanks a ton!
The Finder sidebar isn't a table-view it's a Source List NSOutlineView:
The border is applied around the enclosing scroll view:
Note also that a standard NSOutlineView lets you adjust the highlight style from within Interface Buider:
In my experience selected rows are still painted blue, even when the "Source List" highlight style is selected. To avoid that, I needed to prevent the table or outline view from becoming the first responder by subclassing it and adding
- (BOOL)becomeFirstResponder {
return NO;
}
Edit:
Turns out becomeFirstResponder is actually important if you want to support keyboard navigation. I have found a better solution that does not override becomeFirstResponder.
First, create a custom NSTableRowView subclass with an (overridden) empty setEmphasized: method:
- (void)setEmphasized:(BOOL)emphasized {
// This avoids a blue background when selected in a source list that has first responder status.
}
You can then provide an instance of your custom NSTableRowView class by implementing
- (NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger)row
in your NSTableViewDelegate.
To whoever wants to remove the NSTableView border...
My requirement was to remove the border colour of the NSTableView so that, it should look like a white box. Tried all properties and forums but couldn't find a way to do that. Finally I came up with a dirty hack in the Storyboard which could fix the problem. If someone have a better option, please let us know.
Embed the NSTableView in a CustomBox. Set the Box BorderType as 'None'
Then set the constraints (Left, Top, Right and Bottom) of NSTableView to the containing Box. Set the values to -2. so that the NSTableView border will be outside of the Box
Now in Storyboard, select the 'clipView(NSClipView)' of the NSTableView. clipView is the superView of the NSTableView
Go to the Size Inspector and uncheck the 'Automatically Adjust' property of the "Content Insets"
Set the values to Left=2, Top=2, Bottom=-2 and Right=-2
Thats it.
First i need some background color on the text only. Like the headers in the F-Script Browser
Setting [cell setBackgroundColor: [NSColor blueColor]]; colors the whole cell space not only the text. Also i would need underlined and strikeout text. And to make things readable i would finally like to change the colors (foreground/background) of the selection on the styled items.
Can i do this with the default NSTextFieldCell ?
Nearly all of these things are jobs for NSAttributedString. As long as the text field cell has rich text enabled, it should accept an attributed string as its object value just fine.
As for the selection color, remember that an NSTextFieldCell is a kind of NSActionCell, and an NSActionCell is a kind of NSCell. NSCells have a method you can override to return a different highlight color. That covers the background; for the foreground, you may have to draw at least the highlighted portion yourself. You may be able to make good use of blend modes in that method.
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).
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