Why are my images in my NSTableView faded out? - cocoa

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.

Related

How to place an NSButton over an NSTableView

1) No table behind button
2) Table loaded
3) After scrolling
If I place a button over an NSTableView I get artifacts being left behind after scrolling. Does anyone know how to fix this?
My current solution is just to split the section with the table into 2. The lower portion is a disabled button in the background.
Try the NSScrollView method
- (void)addFloatingSubview:(NSView *)view forAxis:(NSEventGestureAxis)axis
All tableviews should normally be inside a ScrollView.
I had a similar problem and solved it, see Why does an NSTextField leave artifacts over an NSTableView when the table scrolls?. Essentially OSX will draw the contents of the table and let the parent scroll view move the cached contents avoiding redraws to be performant. By subclassing the parent scroll view it can be forced to refresh the table hooking the reflectScrolledClipView: method. Then the whole table, including overlays, will be redrawn with each scroll.
That's because the scroll view is set to copy its contents when scrolling and only redraw the newly-uncovered part as a performance optimization. To turn that off, use
myTableView.enclosingScrollView.contentView.copiesOnScroll = NO;
though that will make scrolling use more CPU (you can also do this in the XIB, look for a 'copies on scroll' checkbox).
Probably a better approach would be to switch the scroll view and the button to be layer-backed:
myTableView.enclosingScrollView.wantsLayer = YES;
myButtonView.wantsLayer = YES;
(Again, you can set this in the 'Layers' inspector of the XIB file, where you can click a checkbox next to each view to give it a layer) Now, the scroll view will only copy stuff from its own layer (which no longer includes your button). Also, now all the compositing of the text view will be done using in the graphics card. This works fine with an opaque push button, however, if you put text on a transparent background in its own layer (e.g. if you have a transparent pushbutton with a title), you lose sub-pixel anti-aliasing.

NSOutlineView badges in NSSplitView

I have an NSOutlineView which I draw badge numbers to the right side of cells using drawAtPoint:, NSAttributedString, and of course NSBezierPath. My problem exists when resizing of the outline view occurs when within a subview of an NSSplitView. The badges move along with the resize to the left or right. When they get to the text of the cells themselves they do not stop or truncate the text under them. It just flies right over.
Is there a way to have the cell recognize the custom drawn view next to it and truncate text accordingly? I have tried the solution PXSourceList already, but that did not help either.
"PXSourceList solution" working good. You subclass NSOutlineView and overload frameOfCellAtColumn for this particular task. At this function you need to decrease width of cellFrame, returned from super call, by the width of your badge plus padding.

An NSButton with two combined images (Cocoa OSX)

I want to make a type of popupbutton sort of like the action button on OSX. I need to make the button have two images makeup the representation of the button (the icon for the button and the downward facing disclosure triangle next to it). I was thinking maybe I could add the second image as a subview of the button but it seems that there should be a simpler way to do this. Any ideas?
Make an NSPopUpButton whose pullsDown is set to YES (Type of “Pull Down” in IB) and whose image is set to the image named NSImageNameActionTemplate (“NSActionTemplate” in IB).

Making an NSButton resize its image (Cocoa OSX)

I could not find a way in the documentation to tell an NSButton to resize its image to fill up the whole button. Is there a way to do this programatically?
The closest you'll get is -setImageScaling: ... look up the constants to see how the image will be scaled within the button cell, given its bordered state and bezel type.
If you're looking to replace the standard button entirely with your image (ie, the button cell doesn't draw itself at all - your image serves as the entire visual representation), turn off the border (-setBordered:).
All of these options can be configured in IB as well. A tip: in IB, hover the mouse over any setting in the inspector panel - most if not all give you a hint that shows what method controls the behavior affected by the setting's control.

How can I change the way NSButtonCell objects highlight when clicked?

I am using several NSButtonCell objects in an NSTableView. They are simple square buttons with custom images on them.
These buttons draw properly when they are not highlighted: all that is visible is the image, and the rest of the button rectangle is transparent. However, when I click on them, the entire button rectangle is highlighted, inverting the background in the parts that were transparent.
I would prefer to see the image drawn inverted, and the transparent parts remain transparent. How can this be done?
Try setting your cell's highlightsBy property to NSContentsCellMask. I think you'll have to do this in code (probably in awakeFromNib); I don't see a way to do it in IB alone.
You can do it in Interface Builder too. I use "Square Button" so the button alters between two images (so the image is not inverted at all).
Your buttons behaviour is probably set to "Momentary Light" or "Momentary Push In".
Set the Behaviour to "Momentary Change", and it should work.

Resources