2

I'm not sure if this is possible but I have been trying to create a pause button out of CALayers. I have created a circle and can add the pause rectangles into the middle fine. However the pause lines are of a specified colour and I want them to be transparent to see through to the backgrounds view.

Currently I have a custom view, which has a circle layer and then the pause layers. Is there a way to cut out the rectangles from the circle layer so whatever view it is placed on shows through there

Thanks in advance

  • Have you looked at the `mask` property? How far did that get you? – David Rönnqvist Jan 31 '14 at 12:10
  • I created a small rect using CAShapeLayer and set this as the .mask property for the circle layer, but then all but the line disappeared, as its obviously clipping anything outside that lines path – user2067925 Jan 31 '14 at 12:13
  • Did you try and [search for something like "calayer invert mask"](http://stackoverflow.com/search?q=calayer+invert+mask) and look at those results? The [very first search result](http://stackoverflow.com/a/15376745/608157) seems to be what you are asking for. – David Rönnqvist Jan 31 '14 at 12:22
  • Not sure how i missed that one, just having a look at it now, thanks! – user2067925 Jan 31 '14 at 12:52

1 Answers1

0

You can fill the pause rectangle with transparent color.

[layer setFillColor:[UIColor colorWithRed:1 green:0 blue:0 alpha:.7].CGColor];

or

CGContextSetFillColorWithColor(cpntext, [UIColor colorWithRed:1 green:0 blue:0 alpha:.7].CGColor);

see the .7 alpha i used.

For example below code creates a transparent rectangle

    CAShapeLayer *layer =[CAShapeLayer layer];
    [layer setFrame:CGRectMake(0, 0, 100, 100)];
    UIBezierPath *path =[UIBezierPath bezierPathWithRect:CGRectMake(20, 20, 20, 80)];

    [layer setFillColor:[UIColor colorWithRed:1 green:0 blue:0 alpha:.7].CGColor];
    [layer setPath:path.CGPath];
    [self.view.layer addSublayer:layer];
santhu
  • 4,796
  • 1
  • 21
  • 29