我已经在Swift4中有一条折线,我怎么能把它的风格改成Dashed / Dotted线?
let path = GMSMutablePath(path: GMSPath())
for marker in markerList {
bounds = bounds.includingCoordinate(marker.position)
path.add(marker.position)
}
let polyline = GMSPolyline(path: path)
polyline.strokeColor = UIColor(named: "Primary")!
polyline.strokeWidth = 3.0
polyline.geodesic = true
polyline.map = mapView
答案 0 :(得分:1)
您需要实施func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer
委托方法并使用renderer.lineDashPhase
和renderer.lineDashPattern
属性,您应该能够获得所需内容
代码示例
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
let renderer = MKPolylineRenderer(overlay: overlay)
renderer.strokeColor = UIColor.red
renderer.lineWidth = 4.0
renderer.lineDashPhase = 2
renderer.lineDashPattern = [NSNumber(value: 1),NSNumber(value:5)]
return renderer
}
<强>结果强>