I have a method that accepts a UIBezierPath as a parameter and draws a shape accordingly. If I fill the shape with a solid colour it renders fine but if I try to make it a colour with alpha, I first get an ARC warning asking to change the code and use a bridge and then the fill colour does not render at all.
This works, but is not what I want:
standShapeLayer.fillColor = [[UIColor redColor] CGColor];
This generates an ARC warning "implicit conversion of Objective C pointer type UIColor to C pointer CGColorRef".
standShapeLayer.fillColor = [UIColor colorWithRed:0.2 green:0.66 blue:0.86 alpha:2.0f];
This runs but no fillColor is applied to the shape:
standShapeLayer.fillColor = (__bridge CGColorRef)([UIColor colorWithRed:0.2 green:0.66 blue:0.86 alpha:2.0f]);
Here is the whole code for the method:
-(void)drawShape:(UIBezierPath *)standShape {
[standShapeLayer removeFromSuperlayer];
selectedStand = standShape;
standShapeLayer = [CAShapeLayer layer];
standShapeLayer.path = standShape.CGPath;
standShapeLayer.fillColor = (__bridge CGColorRef)([UIColor colorWithRed:0.2 green:0.66 blue:0.86 alpha:2.0f]);
NSLog(@"color = %@", standShapeLayer.fillColor); // This logs the correct colour which is not rendered.
// standShapeLayer.fillColor = [[UIColor redColor] CGColor]; << This works but is not what I need.
standShapeLayer.strokeColor = [[UIColor redColor] CGColor];
standShapeLayer.lineWidth = 2;
[_imageView.layer addSublayer:standShapeLayer];
}
What do I need to do to allow colours with alpha to fill CAShapeLayer shapes?