I'm trying to draw a transparent highlight color in my TableView pretty simply:
if ([self isSelected]){
self.alphaValue = 0.5f;
NSColor * fillColor = [NSColor colorWithCalibratedRed: 100.0f/256.0f
green: 100.0f/256.0f
blue: 100.0f/256.0f
alpha: 0.5];
[fillColor drawSwatchInRect:dirtyRect];
}
It draws something a bit odd though, a digonal line between the original color and the new alpha color. I know the solution is probably something pretty simple-- but I can't seem to figure out what it is. Any ideas?
I think this is just what
drawSwatchInRect:
is designed to do. When you have any alpha value, the swatch shows how your color looks when composited with black (upper left) and white (lower right). Wherever Apple UI components display a color, they do this. It's more obvious if the color you're using is not a shade of gray.If you want to fill a rectangle with a specific color, letting the background show through, try this:
While this will work for filled rects, note that
dirtyRect
is not always the same shape. For most drawing, you want to use thebounds
of the view being drawn.