可以帮我制作MKPolyline带有附加参数颜色的自定义吗?
CustomPolyline.swift
import Foundation
import MapKit
class CustomPolyline : MKPolyline {
let coordinates: UnsafeMutablePointer<CLLocationCoordinate2D>
let count : Int = 0
let color : String = "ff0000"
init(coordinates: UnsafeMutablePointer<CLLocationCoordinate2D>, count: Int, color: String) {
self.coordinates = coordinates
self.count = count
self.color = color
}
}
Run Code Online (Sandbox Code Playgroud)
在里面
Polyline = CustomPolyline(coordinates: &Path, count: Path.count, color: "ff0000")
self.mapView.addOverlay(Polyline)
func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer! {
if (overlay is CustomPolyline) {
var pr = MKPolylineRenderer(overlay: overlay);
pr.strokeColor = UIColor.colorWithRGBHex(0xff0000).colorWithAlphaComponent(0.5);
pr.lineWidth = …Run Code Online (Sandbox Code Playgroud) 我收到了这个错误
"Nil与返回类型'MKOverlayRenderer'不兼容".
这是我的代码:
func mapView(mapView: MKMapView, rendererForOverlay overlay: MKOverlay) -> MKOverlayRenderer {
if overlay is MKCircle {
let circleRenderer = MKCircleRenderer(overlay: overlay)
circleRenderer.lineWidth = 1.0
circleRenderer.strokeColor = UIColor.purpleColor()
circleRenderer.fillColor = UIColor.purpleColor().colorWithAlphaComponent(0.4)
return circleRenderer
}
return nil
}
Run Code Online (Sandbox Code Playgroud)
它为什么会发生?