0

I'm trying to add a border to an NSWindow for a drag operation (in the same way that dragging into a Finder window puts a blue border around it). The problem I'm experiencing is that the border is drawn underneath all of the subviews in the window.

Note, in the interests of simplicity I've left out the code in MyWindowController, which calls draggingEntered, draggingExited and performDragOperation. I've also removed the code that removes the border - if the code as it stands is run then the window will always have a yellow border under the subviews because the problem that I need to solve is the layering rather than anything else.

@implementation MyWindowView

- (void)drawRect:(NSRect)dirtyRect {
    
    [NSColor.yellowColor set]; // just for debug purposes because I don't use yellow for any other reason
    NSBezierPath *path = [NSBezierPath bezierPathWithRect:self.bounds];
    path.lineWidth = 10.0; 
    
    [path stroke];
}

@end

How do I need to implement this so that the border is drawn on top of the subviews?

4
  • 1
    Where is the MyWindowView view in the view hierarchy?
    – Willeke
    Commented Mar 14, 2023 at 1:36
  • That's exactly the point isn't it? It's at the bottom of the pile - so the only solution I can think of (and I'm trying to see if there's a better way) is to create a new view which sits on top of all the others, and is just the border. But… Apple has clearly solved this problem already (Finder etc) so is there a standard way of achieving this end that I'm missing?
    – headbanger
    Commented Mar 14, 2023 at 8:46
  • 1
    Is the MyWindowView the content view? Do you want to add a border to a view (code) or a window (title of the question)? How do I get a drop target indication on a Finder window?
    – Willeke
    Commented Mar 14, 2023 at 9:24
  • I think that you're right - when dropping into Finder it's the view that gets highlighted. So, in this case, it would be the contentView of the NSWindow (i.e. the border is drawn around the content excluding the titlebar and toolbar, rather than around the entire window itself). Thank you for clarifying my thinking - and in doing so helping understand the answer for myself. I think that this question should be closed as badly worded. Thank you for your help.
    – headbanger
    Commented Mar 14, 2023 at 12:56

0

Browse other questions tagged or ask your own question.