Reputation: 1239
I am using the following code to display an image on the screen.
The class is a an NSViewController subclass.
-(void) loadView{
[super loadView];
CALayer * layer = [ CALayer layer ] ;
NSImage * image = [[ NSImage alloc ] initWithContentsOfURL:[ NSURL URLWithString:@"http://etc-mysitemyway.s3.amazonaws.com/icons/legacy-previews/icons/glossy-black-icons-sports-hobbies/044450-glossy-black-icon-sports-hobbies-ball-beach.png" ] ] ;
layer.contents = image ;
layer.bounds = (CGRect){ .size = { 600, 600 } } ;
[((NSView*)self.view).layer addSublayer:layer ] ;
}
When I run the code I dont see any image on screen.I want to show this image on the screen.I should also add that there are other images in the nib as well.I want this image on top of all other images.
Upvotes: 0
Views: 155
Reputation: 56625
The layer of your view is nil
because you haven't told the view that is wants a layer:
[self.view setWantsLayer:YES];
Upvotes: 3