我在填写叠加层时遇到问题。我想使用一种新颜色。我在这里先向您的帮助表示感谢。
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)
mapView.addOverlay(polygon)
}
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
}
最佳答案
如果您想要使用strokeColor
为您的多边形绘制轮廓,您必须为您的MKPolygonRenderer
设置lineWidth
。默认值为 0
。
但是,你说“填充叠加层”。如果您的意图是填充它,则应使用 fillColor
,而不是 strokeColor
。
(当然,我还要确保您已正确指定 map View 的 delegate
,并且您的 rendererForOverlay
已被调用。在其中添加断点和/或日志语句,并确保正确调用该例程。)
关于ios - Swift 如何用新颜色填充叠加层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38110555/