本文介绍了如何在Mapkit中以不同的颜色绘制两条折线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我绘制第一条线的代码,换另一种颜色的线我该怎么办?????
this is my code for drawing first Line,for another line with another color how can i do ?????
func mapView(mapView : MKMapView! , rendererForOverlay overlay: MKOverlay!) ->MKOverlayRenderer! {
if overlay is MKPolyline {
var polyLineRenderer = MKPolylineRenderer(overlay: overlay)
polyLineRenderer.strokeColor = UIColor.blackColor()
polyLineRenderer.lineWidth = 10
return polyLineRenderer
}
return nil
}
推荐答案
最后,我找到了方法:
在课堂上我放在最重要的位置
In the top of the class i put
var toGo : MKPolyline?
var toCome : MKPolyline?
然后在视图中加载:
var polyLineGoes = MKPolyline(coordinates: &coordinateGoes, count: coordinateGoes.count)
toGo = polyLineGoes
mapView.addOverlay(polyLineGoes)
var polyLineComes = MKPolyline(coordinates: &coordinateComes, count: coordinateComes.count)
toCome = polyLineComes
mapView.addOverlay(polyLineComes)
在课堂结束时:
func mapView(mapView : MKMapView! , rendererForOverlay overlay: MKOverlay!) ->MKOverlayRenderer! {
if overlay is MKPolyline {
if ( toGo != nil) && (toCome != nil ) {
if overlay as? MKPolyline == toGo {
var polyLineRenderer = MKPolylineRenderer(overlay: overlay)
polyLineRenderer.strokeColor = UIColor.redColor()
polyLineRenderer.lineWidth = 3
return polyLineRenderer
} else if overlay as? MKPolyline == toCome {
print(overlay.description)
var polyLineRenderer = MKPolylineRenderer(overlay: overlay)
polyLineRenderer.strokeColor = UIColor.blueColor()
polyLineRenderer.lineWidth = 3
return polyLineRenderer
}
}
}
return nil
}
这篇关于如何在Mapkit中以不同的颜色绘制两条折线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!