我在填写套印本时遇到困难。我想用一种新颜色。谢谢你事先的帮助。
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
为多边形绘制轮廓,则必须为lineWidth
设置MKPolygonRenderer
。默认值为0
。
但是,你说“填充覆盖层”。如果您的目的是填写它,您可以使用fillColor
,而不是strokeColor
。
(当然,我也会确保您正确地指定了地图视图的delegate
,并且您的rendererForOverlay
被调用。在其中添加断点和/或日志语句,并确保正确调用例程。)
关于ios - Swift如何用新颜色填充叠加层,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38110555/