使MKMapView的背景颜色变暗而不会使MKOverlay变暗

时间:2013-04-26 02:40:03

标签: ios mkmapview uibackgroundcolor

如何使MKMapView的背景颜色变暗, NOT 同时使MKOverlay的{​​{1}}变暗 - 类似到Nike + app的地图视图。

2 个答案:

答案 0 :(得分:7)

好的,我在这里得到了解决方案,在向地图添加其他叠加层之前,您可以将总叠加层添加为地图的背景,因此地图的背景颜色会发生变化,但叠加层仍然像之前一样,这是代码

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];

答案 1 :(得分:1)

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)