title: How to get text in a CATextLayer to be clear
body: <p>I've made a <code>CALayer</code> with an added <code>CATextLayer</code> and the text comes out blurry.  In the docs, they talk about "sub-pixel antialiasing", but that doesn't mean much to me.  Anyone have a code snippet that makes a <code>CATextLayer</code> with a bit of text that is clear?</p>
  
  <p>Here's the text from Apple's documentation:</p>
  
  <blockquote>
    <p>Note: CATextLayer disables sub-pixel antialiasing when rendering text.
    Text can only be drawn using sub-pixel antialiasing when it is
    composited into an existing opaque background at the same time that
    it's rasterized. There is no way to draw subpixel-antialiased text by
    itself, whether into an image or a layer, separately in advance of
    having the background pixels to weave the text pixels into. Setting
    the opacity property of the layer to YES does not change the rendering
    mode.</p>
  </blockquote>
  
  <p>The second sentence implies that one can get good looking text if one <code>composites</code> it into an <code>existing opaque background at the same time that it's rasterized.</code>  That's great, but how do I composite it and how do you give it an opaque background and how do you rasterize  it?</p>
  
  <p>The code they use in their example of a Kiosk Menu is as such: (It's OS X, not iOS, but I assume it works!)</p>
  
  <pre><code>NSInteger i;
  for (i=0;i&lt;[names count];i++) {
      CATextLayer *menuItemLayer=[CATextLayer layer];
      menuItemLayer.string=[self.names objectAtIndex:i];
      menuItemLayer.font=@"Lucida-Grande";
      menuItemLayer.fontSize=fontSize;
      menuItemLayer.foregroundColor=whiteColor;
      [menuItemLayer addConstraint:[CAConstraint
           constraintWithAttribute:kCAConstraintMaxY
                        relativeTo:@"superlayer"
                         attribute:kCAConstraintMaxY
                            offset:-(i*height+spacing+initialOffset)]];
      [menuItemLayer addConstraint:[CAConstraint
           constraintWithAttribute:kCAConstraintMidX
                        relativeTo:@"superlayer"
                         attribute:kCAConstraintMidX]];
      [self.menuLayer addSublayer:menuItemLayer];
  } // end of for loop 
  </code></pre>
  
  <p>Thanks!</p>
  
  <hr>
  
  <p>EDIT: Adding the code that I actually used that resulted in blurry text.  It's from a related question I posted about adding a <code>UILabel</code> rather than a <code>CATextLayer</code> but getting a black box instead.  <code>http://stackoverflow.com/questions/3818676/adding-a-uilabels-layer-to-a-calayer-and-it-just-shows-black-box</code></p>
  
  <pre><code>CATextLayer* upperOperator = [[CATextLayer alloc] init];
  CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
  CGFloat components1[4] = {1.0, 1.0, 1.0, 1.0};
  CGColorRef almostWhite = CGColorCreate(space,components1);
  CGFloat components2[4] = {0.0, 0.0, 0.0, 1.0};
  CGColorRef almostBlack = CGColorCreate(space,components2);
  CGColorSpaceRelease(space);
  upperOperator.string = [NSString stringWithFormat:@"13"];
  upperOperator.bounds = CGRectMake(0, 0, 100, 50);
  upperOperator.foregroundColor = almostBlack;
  upperOperator.backgroundColor = almostWhite;
  upperOperator.position = CGPointMake(50.0, 25.0);
  upperOperator.font = @"Helvetica-Bold";
  upperOperator.fontSize = 48.0f;
  upperOperator.borderColor = [UIColor redColor].CGColor;
  upperOperator.borderWidth = 1;
  upperOperator.alignmentMode = kCAAlignmentCenter;
  [card addSublayer:upperOperator];
  [upperOperator release];
  CGColorRelease(almostWhite);
  CGColorRelease(almostBlack);
  </code></pre>
  
  <hr>
  
  <p>EDIT 2:  See my answer below for how this got solved.  sbg.</p>