How to change the color of a MGLPolyline?

后端 未结 2 1147
我在风中等你
我在风中等你 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
      }
    
    0 讨论(0)
  • 2021-01-27 13:48

    You have to make mapView.delegate = self

    Then implement this method:

    func mapView(_ mapView: MGLMapView, strokeColorForShapeAnnotation annotation: MGLShape) -> UIColor {
    
      return .blue
    }
    
    0 讨论(0)
提交回复
热议问题