2

I searched over the internet but I couldn't find an answer to this. Is possible to draw polygon filled with some pattern? I don't wanna use 3rd party libraries. I would like to achieve something similar to this: polygon with pattern

P.Mol
  • 141
  • 2
  • 6

1 Answers1

0

Yes you can do this.

UIColor has an initializer for pattern images.

guard let image = UIImage(named: "Name of the asset") else { return }
let color = UIColor(patternImage: image)

Then in your overlay renderer delegate method, you can simply assign it to your fill color.

func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {

    // Renderer code

    yourRenderer.fillColor = color

    // Return your renderer

}
Desdenova
  • 5,326
  • 8
  • 37
  • 45
  • Thank You. This allows me for filling polygon with patter but what in case when i would like to fill polygon with pattern and have some background color? – P.Mol Dec 14 '18 at 08:06
  • I think the easiest way would be changing the pattern image's background color. – Desdenova Dec 14 '18 at 08:11