Simple dim overlay on iOS MapView, covering entire map using MKOverlay and MKOverlayRenderer with customizable color and alpha values.
Initialize and add MapDimOverlay to your MKMapView object.
func addDimOverlay() {
let dimOverlay : DimOverlay = DimOverlay(mapView: mapView)
mapView.add(dimOverlay)
}In the map view's delegate's mapView: rendererFor overlay: method, instantiate and return MapDimOverlayRenderer.
You can customize overlay color and opacity.
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
if overlay is DimOverlay {
return DimOverlayRenderer(overlay: overlay, dimAlpha: 0.3, color: .blue)
}
return MKOverlayRenderer(overlay: overlay)
}You can directly add the MapDimOverlay.swift, and MKMapDimOverlayRenderer.swift files to your project.
- Download the latest code version or add the repository as a git submodule to your git-tracked project.
- Open your project in Xcode, then drag and drop
MapDimOverlay.swift, andMKMapDimOverlayRenderer.swiftonto your project (use the "Project Navigator view"). Make sure to select Copy items when asked if you extracted the code archive outside of your project.
This code is distributed under the Unlicense.


