MKMapDimOverlay
Simple dim overlay on iOS MKMapView, covering entire map using MKOverlay and MKOverlayView with customisable colour and alpha values.
Install / Use
/learn @lukya/MKMapDimOverlayREADME
MKMapDimOverlay
There is a Swift version of this :).
Simple dim overlay on iOS MKMapView, covering entire map using MKOverlay and MKOverlayView with customizable colour and alpha values.
Usage
Initialize and add MKMapDimOverlay to your MKMapView object.
- (void)addDimOverlay {
MKMapDimOverlay *dimOverlay = [[MKMapDimOverlay alloc] initWithMapView:self.mapView];
[self.mapView addOverlay: dimOverlay];
}
And in map view's mapView: rendererForOverlay: delegate method, instantiate and return MKMapDimOverlayView. You can customize overlay color and opacity.
-(MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay {
if([overlay isMemberOfClass:[MKMapDimOverlay class]]) {
MKMapDimOverlayView *dimOverlayView = [[MKMapDimOverlayView alloc] initWithOverlay:overlay];
dimOverlayView.overlayAlpha = 0.3;
dimOverlayView.overlayColor = [UIColor magentaColor];
return dimOverlayView;
}
return nil;
}
Adding MKMapDimOverlay to your project
CocoaPods
CocoaPods is the recommended way to add MKMapDimOverlay to your project.
- Add a pod entry for MKMapDimOverlay to your Podfile
pod 'MKMapDimOverlay' - Install the pod(s) by running
pod install. - Include MKMapDimOverlay wherever you need it with
#import "MKMapDimOverlay.h"and#import "MKMapDimOverlayView.h".
Source files
Alternatively you can directly add the MKMapDimOverlay.h, MKMapDimOverlay.m, MKMapDimOverlayView.h and MKMapDimOverlayView.m source 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
MKMapDimOverlay.h,MKMapDimOverlay.m,MKMapDimOverlayView.handMKMapDimOverlayView.monto your project (use the "Product Navigator view"). Make sure to select Copy items when asked if you extracted the code archive outside of your project. - Include MKMapDimOverlay wherever you need it with
#import "MKMapDimOverlay.h"and#import "MKMapDimOverlayView.h".
Static library
You can also add MKMapDimOverlay as a static library to your project or workspace.
- 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
MKMapDimOverlay.xcodeprojonto your project or workspace (use the "Product Navigator view"). - Select your target and go to the Build phases tab. In the Link Binary With Libraries section select the add button. On the sheet find and add
libMKMapDimOverlay.a. You might also need to addMKMapDimOverlayto the Target Dependencies list. - Include MKMapDimOverlay wherever you need it with
#import "MKMapDimOverlay.h"and#import "MKMapDimOverlayView.h".
Screenshots
No Overlay

Default Overlay (Color : Black | Opacity 0.2)

Custom Overlay (Color : Cyan | Opacity 0.3)

License
This code is distributed under the terms and conditions of the MIT license.
