Search code examples
iosmkmapviewuibackgroundcolor

Darkening the MKMapView's background color without darkening the MKOverlay


How would one darken the MKMapView's background color, and NOT darken the MKOverlay in the MKMapView's at the same time -- similar to the map view in the Nike+ app.


Solution

  • OK , I got the solution here ,before add other overlays to the map ,you can add a total overlay as a background to the map ,so the map's background color is changed ,but the overlay is still as they are before ,here are codes

    MKMapRect worldRect = MKMapRectWorld;
        MKMapPoint point1 = MKMapRectWorld.origin;
        MKMapPoint point2 = MKMapPointMake(point1.x+worldRect.size.width,point1.y);
        MKMapPoint point3 = MKMapPointMake(point2.x, point2.y+worldRect.size.height);
        MKMapPoint point4 = MKMapPointMake(point1.x, point3.y);
    
        MKMapPoint points[4] = {point1,point2,point3,point4};
        self.polygon = [MKPolygon polygonWithPoints:points count:4];
        [self.runMapView addOverlay:self.polygon];