2010-07-20 13 views

Respuesta

14

Utilice un CAShapeLayer como la máscara para la capa que desea recortar. CAShapeLayer tiene una propiedad de ruta que toma un CGPathRef.

1

Sí, puede anular el drawInContext de su capa personalizada.

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) 
} 

O puede crear una CAShapeLayer como máscara.