Question

I have a custom NSView in an NSScrollView. I am trying to draw a focus ring round an NSScrollView (or perhaps the NSClipView) so that when my custom view receives a drag-drop hover the scroll view appears to get focus. How on earth do I do this? I don't want to have to subclass NSScrollView ... do I?

Was it helpful?

Solution

Two approaches:

NSClipView Subclass

Subclass NSClipView and swap it out at runtime (mind-blowingly easy). The subclass would respond to the drop validation method by drawing whatever effect you want just inside its bounds. Maybe an NSBezierPath with a rectangle made from the clip view's -bounds.

Document View

Your document view (the view inside the scroll view) asks its -enclosingScrollview for its -documentVisibleRect and draws a rectangle on itself just like the NSClipView subclass method above (ie, the same drawing approach in response to the drag and drop validation method being called).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top