任何人都可以帮助我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
}
}
在里面
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 = 10;
return pr;
}
return nil
}
我的解决方案不起作用,我不知道为什么。折线根本不可见。我是 SWIFT 的初学者,所以我认为问题出在我的CustomPolyline
课堂上。感谢帮助。