Caleb Caleb - 3 months ago 19
Swift Question

Swift how to fill in overlay with a new color

I am having trouble filling in the overlay. I would like to use a new color. Thanks for the help in advance.

func addBoundry()
var points=[CLLocationCoordinate2DMake(39.02, -76.9),CLLocationCoordinate2DMake(38.97, -76.9),CLLocationCoordinate2DMake(38.97, -77),CLLocationCoordinate2DMake(39.02, -77)]

let polygon = MKPolygon(coordinates: &points, count: points.count)


let regionRadius: CLLocationDistance = 1000
func centerMapOnLocation(location: CLLocation) {
let coordinateRegion = MKCoordinateRegionMakeWithDistance(location.coordinate,
regionRadius * 2.0, regionRadius * 2.0)
mapView.setRegion(coordinateRegion, animated: true)
func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer! {
if overlay is MKPolygon {
let polygonView = MKPolygonRenderer(overlay: overlay)
//polygonView.strokeColor = UIColor.magentaColor()
polygonView.strokeColor = UIColor(red: 0/255.0, green: 180/255.0, blue: 0/255.0, alpha: 0.4)

return polygonView

return nil

Rob Rob

If you want an outline to your polygon with strokeColor, you have to set lineWidth for your MKPolygonRenderer. The default value is 0.

But, you say "filling in the overlay". If your intent was to fill it in, you'd use fillColor, not strokeColor.

(Of course, I'd also make sure that you've specified the delegate of the map view, properly and that your rendererForOverlay is getting called at all. Add a breakpoint and/or log statement in there and make sure that routine is getting called properly.)