Can't stroke path after filling it
When you paint a path, either by stroking it or by filling it, the graphics context resets its path to empty. So after you call CGContextFillPath
, the context doesn't have a path to stroke.
Instead of trying to fill the path and then stroke it, you can use the CGContextDrawPath
function to do both in one call:
CGContextDrawPath(ctx, kCGPathFillStroke);
The kCGPathFillStroke
constant tells Core Graphics to fill the path and then stroke it.
On the other hand, you could use UIBezierPath
and UIColor
to reduce the amount of code substantially:
-(void)drawRect:(CGRect)rect {
[[UIColor colorWithWhite:0 alpha:0.4] setFill];
[[UIColor whiteColor] setStroke];
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rectRect cornerRadius:12];
path.lineWidth = 4;
[path fill];
[path stroke];
}