title: Antialiasing on CAShapeLayers
body: <p>I have a custom view for a loading indicator which is comprised of a number of <code>CAShapeLayers</code> which I perform various animations on to represent various states. In the init method I create a number of shape layers and add them as sublayers to the view's layer. The issue I'm having is the shapes that I'm drawing have very rough edges and don't seem to be antialiased. I've tried a number of things from similar answers on here but I can't seem to antialias the shapes. I've never had this problem before then drawing directly in <code>drawRect</code>.</p>
  
  <p>Is there anything I'm missing or is there a better way to accomplish what I'm trying to do?</p>
  
  <p>Update: Here's a comparison of how the shapes are being drawn:</p>
  
  <p><img src="https://i.stack.imgur.com/LMTZO.png" alt="Comparison of drawing methods"></p>
  
  <p>On the left I'm drawing in <code>layoutSubviews</code> using this code:</p>
  
  <pre><code>CGFloat lineWidth = 2.5f;
  CGFloat radius = (self.bounds.size.width - lineWidth)/2;
  CGPoint center = CGPointMake(CGRectGetWidth(self.frame)/2, CGRectGetHeight(self.frame)/2);
  
  CGFloat startAngle = - ((float)M_PI / 2);
  CGFloat endAngle = (2 * (float)M_PI) + startAngle;
  
  UIBezierPath *trackPath =  [UIBezierPath bezierPathWithArcCenter:center
                                                            radius:radius
                                                        startAngle:startAngle
                                                          endAngle:endAngle
                                                         clockwise:YES];
  self.trackLayer.path = trackPath.CGPath;
  self.trackLayer.lineWidth = lineWidth;
  </code></pre>
  
  <p>On the right I'm calling a separate method from <code>awakeFromNib</code>:</p>
  
  <pre><code>-(void)awakeFromNib
  {
      ....
      self.trackLayer = [self trackShape]
      [self.layer addSublayer:self.trackLayer];
  }
  
  -(CAShapeLayer*)trackShape
  {
      float start_angle = 2*M_PI*-M_PI_2;
      float end_angle = 2*M_PI*1-M_PI_2;
      float minSize = MIN(self.frame.size.width, self.frame.size.height);
      float radius = (minSize-_strokeWidth)/2 -4;
      CGPoint center = CGPointMake(self.frame.size.width/2,self.frame.size.height/2);
      CAShapeLayer *circle = [CAShapeLayer layer];
  
      circle.path = [UIBezierPath bezierPathWithArcCenter:center
                                                   radius:radius
                                               startAngle:start_angle
                                                 endAngle:end_angle
                                                clockwise:YES].CGPath;
      circle.strokeColor = self.trackColor.CGColor;
      circle.fillColor = nil;
      circle.lineWidth = (_strokeWidth == -1.0) ? minSize * _strokeWidthRatio
      : _strokeWidth;
      circle.rasterizationScale = [[UIScreen mainScreen] scale];
  
      return circle;
  }
  </code></pre>