iOS: UIView with a Dashed line

What I want:
enter image description here
To do this use this code:


      // Important, otherwise we will be adding multiple sub layers
      if ([[[self layer] sublayers] objectAtIndex:0])
            self.layer.sublayers = nil;

        CAShapeLayer *shapeLayer = [CAShapeLayer layer];
        [shapeLayer setBounds:self.bounds];
        [shapeLayer setFillColor:[[UIColor clearColor] CGColor]];
        [shapeLayer setStrokeColor:[[UIColor blackColor] CGColor]];
        [shapeLayer setLineWidth:3.0f];
        [shapeLayer setLineJoin:kCALineJoinRound];
        [shapeLayer setLineDashPattern:
        [NSArray arrayWithObjects:[NSNumber numberWithInt:10],
        [NSNumber numberWithInt:5],nil]];

        // Setup the path
        CGMutablePathRef path = CGPathCreateMutable();
        CGPathMoveToPoint(path, NULL,,;
        CGPathAddLineToPoint(path, NULL,,;

        [shapeLayer setPath:path];

        [[self layer] addSublayer:shapeLayer];

iOS: UIView with a Dashed line iOS: UIView with a Dashed line Reviewed by Ricardo on 10:44 Rating: 5

No hay comentarios:

Con la tecnología de Blogger.