0

I have a layering problem with two existing buttons and a NSImageView. I have a custom view called PhotosView which inherits from NSView with two buttons (arrows):

@interface PhotosView : NSView

- (void)setPhoto:(NSURL *)path;

@end

In the implementation of the setPhoto method I add a photo to the PhotosView:

- (void)setPhoto:(NSURL *)path
{
    [imageView removeFromSuperview];

    imageView = [[NSImageView alloc] initWithFrame:[self frame]];
    [imageView setImage:[[NSImage alloc] initWithContentsOfURL:path]];

    [self addSubview:imageView];
}

The imageView gets added on top of the two buttons. In my research I only found similar problems to iOS-development. The one helpful thread is here: http://www.cocoabuilder.com/archive/cocoa/55873-nsview-subviews-ordering.html, but I can't really believe there isn't an easier solution?

enter image description here

Mirco Widmer
  • 2,139
  • 1
  • 20
  • 44

1 Answers1

2

Change your last line to:

[self addSubview:imageView positioned:NSWindowBelow relativeTo:nil];

(See the API here)

Russell Zahniser
  • 16,188
  • 39
  • 30