Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 484
ximmyxiao Avatar asked Apr 26 '13 02:04

ximmyxiao


2 Answers

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];
like image 195
ximmyxiao Avatar answered Sep 30 '22 15:09

ximmyxiao


Swift 2.0

let worldRect = MKMapRectWorld
let point1 = MKMapRectWorld.origin
let point2 = MKMapPointMake(point1.x + worldRect.size.width, point1.y)
let point3 = MKMapPointMake(point2.x, point2.y + worldRect.size.height)
let point4 = MKMapPointMake(point1.x, point3.y)
var points = [point1, point2, point3, point4]
let polygon = MKPolygon(points: &points, count: points.count)
mapView.addOverlay(polygon)
like image 25
Sping David Avatar answered Sep 30 '22 14:09

Sping David