views:

92

answers:

1

I'm trying to get a CALayer with a black background to display. I've attached the AppDelegate as the delegate to the file's owner. The console reports correctly the "awaking from nib..." log statement. I however, just see a blank grey window (335x390 in size), with no black box drawn in the middle. What concept am I missing?

Thanks in advance for the help,

Charles

#import "AppDelegate.h"
#import <QuartzCore/QuartzCore.h>
@implementation AppDelegate

-(void)awakeFromNib;
{
  NSLog(@"awaking from nib...");
  [[window contentView] setWantsLayer:YES];

  layer = [CALayer layer];
  [layer setBounds:CGRectMake(0.0,0.0,100.0,100.0)];

   // center the animation layer
   [layer setPosition:CGPointMake([[window contentView] frame].size.width/2, [[window contentView]frame].size.height/2)];
   CGColorRef color = CGColorCreateGenericRGB(0., 0., 0., 1);
   [layer setBackgroundColor:color];
   CFRelease(color);

   [layer setBorderWidth:5.0f];

   [[[window contentView] layer] addSublayer:layer];      
}
@end
A: 

The construction code for your custom layer looks correct, although a color with an RGBA of (1,1,1,1) will be white, not black.

I'd verify that your outlet to your window property is connected correctly (make sure it's non-nil), and that the contentView is non-nil. If those are looking good, you could try to provide your own custom layer for the contentView by doing something similar to the following:

[[window contentView] setLayer:[CALayer layer]];
[[window contentView] setWantsLayer:YES];
Brad Larson
Brad,Thanks for correcting me on the color issue. I just modified it in the question so it wouldn't be confusing later on for others. Yes, the "window" property was the missing concept I didn't have. Thanks!
Charles