title: Sublayer is not visible unless added after viewDidAppear
body: <p>I am trying to load a profile image for an app, but I want to add a white border to it and make it circular before I display it. In order to do that I set the image property on the UIImageView and then prepare the image by setting the appropriate corner radius, masking it to the bounds and then adding a white border sublayer. Originally, I was loading the image in over the internet asynchronously and everything worked fine because the image appeared after the view had appeared. However, when I cached the image and tried to prepare it before the imageView was shown on screen I couldn't get the border sublayer to display. It still masked properly, just no border. The code that I am using to prepare the image is below.</p>
  
  <pre><code>- (void)prepareProfileImage
  {
      CALayer *imageLayer = self.profileImageView.layer;
      imageLayer.borderColor = [UIColor whiteColor].CGColor;
      imageLayer.allowsEdgeAntialiasing = NO;
      [imageLayer setCornerRadius:PROFILE_IMAGE_DIAMETER/2.0];
      [imageLayer setMasksToBounds:YES];
  
      CALayer *borderLayer = [CALayer layer];
      CGRect borderFrame = CGRectMake(-1.0, -1.0, (self.profileImageView.frame.size.width+2.0), (self.profileImageView.frame.size.height+2.0));
      [borderLayer setBackgroundColor:[[UIColor whiteColor] CGColor]];
      [borderLayer setFrame:borderFrame];
      [borderLayer setCornerRadius:PROFILE_IMAGE_DIAMETER/2.0];
      [borderLayer setBorderWidth:PROFILE_IMAGE_BORDER_WIDTH+1.0];
      [borderLayer setBorderColor:[UIColor whiteColor].CGColor];
  
      [imageLayer addSublayer:borderLayer];
  }
  </code></pre>
  
  <p>This method works fine as long as it's called after viewDidLoad, but will not add the border layer if called before viewDidLoad. I have confirmed that self.profileImageView has been allocated at the time of this method call, but I only get the circular image, no border.</p>
  
  <p>Is there something that I am misunderstanding about CALayers? Should it matter when I add the layer as a sublayer?</p>
  
  <p>The reason I am not using the border property directly on the image layer is that it leaves a tiny sliver of image around the outside that is displeasing.</p>