Darkening the MKMapView's background color wit

2019-03-20 19:19发布

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.

2条回答
干净又极端
2楼-- · 2019-03-20 19:41

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];
查看更多
放荡不羁爱自由
3楼-- · 2019-03-20 19:50

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)
查看更多
登录 后发表回答