自定义多边形类可更改笔触颜色

时间:2016-01-10 23:57:56

标签: swift2

我正在尝试创建一个自定义多边形类,以便我可以动态更改多边形的笔触颜色,但是我收到错误:

Objective-C method 'mapView:rendererForOverlay:' provided by method 'mapView(_:rendererForOverlay:)' conflicts with optional requirement method 'mapView(_:rendererForOverlay:)' in protocol 'MKMapViewDelegate'

这是我的实施:

self.polygon = CustomPolygon(coordinates: &decodedCoordinates!, count: polygon.coordinates!.count)
self.mapView.addOverlay(self.polygon)

func mapView(mapView: MKMapView, rendererForOverlay overlay: CustomPolygon) -> MKOverlayRenderer {

    let polygonRenderer = MKPolygonRenderer(overlay: overlay)
    polygonRenderer.lineWidth = 3

    polygonRenderer.strokeColor = UIColor(rgba: overlay.color)

    return polygonRenderer
}

CustomPolygon.swift

import Foundation
import MapKit

class CustomPolygon : MKPolygon {
    var color: String?
}

我正在尝试按照这个问题How to make custom MKPolyline in SWIFT with additional argument - color,但对于多边形不是折线。

由于

0 个答案:

没有答案