3

I am trying to create an overlay on a map exactly as the picture shows in this post: How to fill outside overlay circle in iOS 7 on map. I have read through these instructions to achieve this 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 get this code to run as an overlay. As you can probably tell i am a bit of a novice at this but this is the first time i have got so stuck i cant work it out from other answers on here!

Community
  • 1
  • 1
  • Isn't simply adding the view as a sublayer to the layer of your main view the solution? – Orion Jul 15 '15 at 12:15

0 Answers0