How to change the color of a MGLPolyline?

后端 未结 2 1146
我在风中等你
我在风中等你 2021-01-27 13:09

How can I change the color of an MGLPolyline? I had looked here but the answer did not work. I also tried some other code but it was too dependant on apple maps. So how can I ch

2条回答
  •  隐瞒了意图╮
    2021-01-27 13:44

    You can set the color and width of a polyline in MKMapViewDelegate function only. Check example below.

      public func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
          let polyLine = overlay as? MKPolyline
          let renderer = MKPolylineRenderer(overlay: overlay)
          renderer.lineWidth = 2.5
          renderer.strokeColor = UIColor(red: 47/255, green: 62/255, blue: 158/255, alpha: 1.0)
          return renderer
      }
    

提交回复
热议问题