Reputation: 3435
I have a code line
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.strokeColor = [UIColor colorWithRed:r green:g blue:b alpha:1.f].CGColor;
Can I rewrite it with our using UIColor
? I mean can I create CGColorRef
from a, r, g, b components and pass it to shapeLayer.strokeColor
, considering using ARC.
Upvotes: 1
Views: 2459
Reputation: 3039
If you want to avoid memory leaks you should release CGColorSpaceRef
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGColorRef aColor = CGColorCreate( colorspace, components );
shapeLayer.strokeColor = aColor;
CGColorRelease( aColor );
CGColorSpaceRelease(colorspace);
Upvotes: 3
Reputation: 3956
Yes you can do that. Try out following
CGColorCreate(CGColorSpaceCreateDeviceRGB(), [1.0, 0.5, 0.5, 1.0]) //array values are in order- red, green, blue, alpha
Upvotes: 0