How to programmatically change map color from day to night in ios7

和自甴很熟 提交于 2019-12-08 20:39:12

问题


I am working on an app for iOS 7, and am trying to change the map from day to night and night to day mode. I have not found any relevant APIs in iOS 7 documentation to do this.


回答1:


This is not a built in feature of MKMapKit so what you are asking is not possible without doing it yourself. If you were going to do it yourself, the best you could do would be to find a map tile source of 'night mode' tiles, and use the MKTileOverlay class (New to iOS 7) to replace the content of the map entirely.

A brief code example using the Open Street Map tile source (Not night tiles!)

// Put this in your -viewDidLoad method
NSString *template = @"http://tile.openstreetmap.org/{z}/{x}/{y}.png";
MKTileOverlay *overlay = [[MKTileOverlay alloc] initWithURLTemplate:template];

//This is the important bit, it tells your map to replace ALL the content, not just overlay the tiles.
overlay.canReplaceMapContent = YES;
[self.mapView addOverlay:overlay level:MKOverlayLevelAboveLabels];

Then implement the mapView delegate method below...

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay {
    if ([overlay isKindOfClass:[MKTileOverlay class]]) {
        return [[MKTileOverlayRenderer alloc] initWithTileOverlay:overlay];
    }
}

For full reference, see https://developer.apple.com/library/ios/documentation/MapKit/Reference/MKTileOverlay_class/Reference/Reference.html



来源:https://stackoverflow.com/questions/21996478/how-to-programmatically-change-map-color-from-day-to-night-in-ios7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!