Search code examples
iosobjective-cuigraphicscontext

What's the difference between CGContextSetStrokeColorWithColor UIColor setStroke?


Is there any difference between those two ways of setting stroke color?

CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor)

[[UIColor redColor] setStroke]

Example

CGContextRef cr = UIGraphicsGetCurrentContext();

CGContextSetStrokeColorWithColor(cr, [UIColor redColor].CGColor);
[[UIColor redColor] setStroke];

UIBezierPath *bp = [UIBezierPath new];

[bp stroke];

UIGraphicsEndImageContext();

Solution

  • One is longer and pure C. The other is shorter and uses Objective-C. They have the same effect.