2010-07-20 11 views

risposta

14

Utilizzare un CAShapeLayer come maschera per il livello che si desidera ritagliare. CAShapeLayer ha una proprietà path che accetta un CGPathRef.

1

Sì, è possibile sovrascrivere il drawInContext del livello personalizzato.

func addPathAndClipIfNeeded(ctx:CGContext) { 
    if (self.path != nil) { 
     CGContextAddPath(ctx,self.path); 
     if (self.stroke) { 
      CGContextSetLineWidth(ctx, self.lineWidth); 
      CGContextReplacePathWithStrokedPath(ctx); 
     } 
     CGContextClip(ctx); 
    } 
} 
override public func drawInContext(ctx: CGContext) { 
    super.drawInContext(ctx) 
    addPathAndClipIfNeeded(ctx) 
} 

Oppure è possibile creare un CAShapeLayer come maschera.