How to fill outer overlay circle on a map using Swift
I am trying to create an overlay on a map exactly as shown in the picture in this post: How to fill an outer overlay circle in iOS 7 on a map . I have read these instructions to achieve this goal in Objective C and tried my best to convert this to swift as shown below:
override func drawMapRect(mapRect: MKMapRect, zoomScale: MKZoomScale, inContext context: CGContext) {
print("overlay")
// Fill full map rect with some color.
let rect: CGRect = rectForMapRect(mapRect)
CGContextSaveGState(context)
CGContextAddRect(context, rect)
CGContextSetFillColorWithColor(context, UIColor.whiteColor().colorWithAlphaComponent(0.4).CGColor)
CGContextFillRect(context, rect)
CGContextRestoreGState(context)
// Clip rounded hole.
CGContextSaveGState(context)
CGContextSetFillColorWithColor(context, UIColor.whiteColor().CGColor)
CGContextSetBlendMode(context, CGBlendMode.Clear)
CGContextFillEllipseInRect(context, rect)
CGContextRestoreGState(context)
// Draw circle
super.drawMapRect(mapRect, zoomScale:zoomScale, inContext:context)
}
I know I am missing how to make this code work as an overlay. As you can probably tell, I'm a bit new to this, but this is the first time I've gotten so stuck I can't handle it from the other answers here!
+3
source to share
No one has answered this question yet
See similar questions:
or similar: