如何在MKPolyline上添加边框

是否可以在Apple Mapview中向多段线添加边框?

PS

只想分享一个解决方案

linnil22 回答:如何在MKPolyline上添加边框

我的实现是在主折线下面添加另一个折线叠加层,其lineWidth比主折线厚// Instantiate the main polyline let polylineObj = MKPolyline(coordinates: yourArrayOfCoords,count: yourArrayOfCoords.count) // Identifier to tell which is which polylineObj.title = "main" // Instantiate the border polyline let borderPolylineObj = MKPolyline(coordinates: yourArrayOfCoords,count: yourArrayOfCoords.count) // Add main polyline appleMapView.addOverlay(polylineObj) // Add border polyline below the main polyline appleMapView.insertOverlay(borderPolylineObj,below: polylineObj) 几像素(可以说是您的边框宽度)。

MKMapViewDelegate

然后使用func mapView(_ mapView: MKMapView,rendererFor overlay: MKOverlay) -> MKOverlayRenderer { let renderer = MKPolylineRenderer(overlay: overlay) // Use different colors for the border and the main polyline renderer.strokeColor = overlay.title == "main" ? .blue : .red // Make the border polyline bigger. Their difference will be like the borderWidth of the main polyline renderer.lineWidth = overlay.title == "main" ? 4 : 6 // Other polyline customizations renderer.lineCap = .round renderer.lineJoin = .bevel return renderer } 函数:

group_by

PS

如果您有更好的实施方法,请回答。这种实现方式的执行成本很高,因为这实际上会使渲染的折线的数量增加一倍。

本文链接:https://www.f2er.com/3120384.html

大家都在问