开发者

Changing color of an MKOverlay that has already been added to a mapview

开发者 https://www.devze.com 2023-03-11 04:32 出处:网络
I have some MKOverlays(actually they are MKPolygons) that are loaded as soon as the map shows up.I would like to change their color dynamically.The only way I can see of doing this, is to remove the o

I have some MKOverlays(actually they are MKPolygons) that are loaded as soon as the map shows up. I would like to change their color dynamically. The only way I can see of doing this, is to remove the overlay then add it back with the new color. Is there a better way to do this on the existing overlay?

I am brand new at objective-c/xcode/ios ... so please be 开发者_开发技巧gentle :)


Your mapView has a method for getting the renderer object for a given overlay. You can then use the renderer to change the color of your overlay.

if let renderer = mapView.rendererForOverlay(overlay) as? MKPolygonRenderer {
    renderer.fillColor = UIColor.redColor()
}

Leave out the optional cast to MKPolygonRenderer if you're not looking for an MKPolygon overlay.

(I realize this is a rather old question, but I just stumbled across it and found my solution

0

精彩评论

暂无评论...
验证码 换一张
取 消