Is there a way to "highlight" a NSImageView with the default highlight color of the mac? I'm simply looking for a way to tint my nsimageview so that the user can identify the object easily.
Thanks,
Kevin
Is there a way to "highlight" a NSImageView with the default highlight color of the mac? I'm simply looking for a way to tint my nsimageview so that the user can identify the object easily.
Thanks,
Kevin
If one of the built-in options of NSImageView isn't sufficient, you could subclass NSImageView, and in drawRect, do:
- (void)drawRect:(NSRect)frame {
[super drawRect:frame]; // this takes care of image
[NSBezierPath setDefaultLineWidth:4.0];
[[NSColor highlightColor] set];
[NSBezierPath strokeRect:frame]; // will give a 2 pixel wide border
}
Ahh, to have it as a variable state, I'd probably define an instance variable then, such as isHighlighted to keep track of that state. Then, whenever anything happens that would change the highlighted state, you'll set the view as needing redisplay. You could do this in the set/get methods for instance:
- (void)setHighlighted:(BOOL)aHighlighted {
isHighlighted = aHighlighted;
[self setNeedsDisplay:YES];
}
Then, update your drawRect: method to take into account the isHighlighted flag. How you achieve an unhighlighted look may depend on the style of image view. You could try just calling super to do the drawing, but if in testing, you see any residual or stray highlighted pixel information that super's drawing didn't overwrite, you may want to first draw clear color, then call super.
So, something like this:
- (void)drawRect:(NSRect)frame {
isHighlighted ? [[NSColor highlightColor] set] : [[NSColor clearColor] set];
[NSBezierPath setDefaultLineWidth:4.0];
if (isHighlighted) {
[super drawRect:frame];
[NSBezierPath strokeRect:frame]; // will give a 2 pixel wide border
} else {
[NSBezierPath fillRect:frame];
[super drawRect:frame];
}
}