Dotted line on map view

前端 未结 2 1620
时光说笑
时光说笑 2021-02-19 09:43

I can create a line between two points fairly easy with the below code (part of it anyways) How could I make the line dotted instead of solid? Also would it be possible to cha

2条回答
  •  梦谈多话
    2021-02-19 09:57

    Answer in Swift

    func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
        guard let polyline = overlay as? MKPolyline else {
            fatalError("Not a MKPolyline")
        }
    
        let renderer = MKPolylineRenderer(polyline: polyline)
    
        renderer.strokeColor = #colorLiteral(red: 0.1764705926, green: 0.4980392158, blue: 0.7568627596, alpha: 1)
        renderer.lineWidth = 8
        renderer.lineDashPattern = [0, 10]
    
        return renderer
    } 
    

提交回复
热议问题