Do this: CGContextSetLineWidth(context, 1); before the stroke is applied.
Stroke not appearing on Circle
-
16-07-2023 - |
質問
I am trying to add a stroke around my hollow circle and its not appearing. Can someone help me please spot where I am going wrong and fix it please. Been stuck on this for ages and nothing seems to work!
This is how it currently looks when I run my code:
I want to add a stroke line around the outside of the hollow circle but my code isn't working and I don't know where I am going wrong. Would really appreciate some help.
Below is my code:
- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context
{
// Fill full map rect with some color.
CGRect rect = [self rectForMapRect:mapRect];
CGContextSaveGState(context);
CGContextAddRect(context, rect);
CGContextSetFillColorWithColor(context, [UIColor colorWithRed:0 green:255 blue:255 alpha:0.4f].CGColor);
CGContextFillRect(context, rect);
CGContextRestoreGState(context);
// Clip rounded hole.
CGContextSaveGState(context);
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
CGContextSetBlendMode(context, kCGBlendModeClear);
CGContextFillEllipseInRect(context, [self rectForMapRect:[self.overlay boundingMapRect]]);
CGContextSetLineWidth(context, 1);
CGContextStrokeEllipseInRect(context, [self rectForMapRect:[self.overlay boundingMapRect]]);
CGContextRestoreGState(context);
// Draw circle
[super drawMapRect:mapRect zoomScale:zoomScale inContext:context];
}
FIXED - WORKING CODE:
// Fill full map rect with some color.
CGRect rect = [self rectForMapRect:mapRect];
CGContextSaveGState(context);
CGContextAddRect(context, rect);
CGContextSetFillColorWithColor(context, [UIColor colorWithRed:0 green:255 blue:255 alpha:0.4f].CGColor);
CGContextFillRect(context, rect);
CGContextRestoreGState(context);
// Clip rounded hole.
CGContextSaveGState(context);
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGContextSetLineWidth(context, 300);
CGContextStrokeEllipseInRect(context, [self rectForMapRect:[self.overlay boundingMapRect]]);
CGContextSetBlendMode(context, kCGBlendModeClear);
CGContextFillEllipseInRect(context, [self rectForMapRect:[self.overlay boundingMapRect]]);
CGContextRestoreGState(context);
// Draw circle
[super drawMapRect:mapRect zoomScale:zoomScale inContext:context];
解決
所属していません StackOverflow