Swift如何使用新颜色填充叠加层 [英] Swift how to fill in overlay with a new color
问题描述
我在填写叠加层时遇到问题.我想使用一种新的颜色.我在这里先向您的帮助表示感谢.
I am having trouble filling in the overlay. I would like to use a new color. Thanks for the help in advance.
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
.
If you want an outline to your polygon with strokeColor
, you have to set lineWidth
for your MKPolygonRenderer
. The default value is 0
.
但是,您说的是填充叠加层".如果要填写,请使用fillColor
,而不是strokeColor
.
But, you say "filling in the overlay". If your intent was to fill it in, you'd use fillColor
, not strokeColor
.
(当然,我还要确保您已正确指定了地图视图的delegate
,并且您的rendererForOverlay
都已被调用.在其中添加一个断点和/或log语句并确保该例程被正确调用.)
(Of course, I'd also make sure that you've specified the delegate
of the map view, properly and that your rendererForOverlay
is getting called at all. Add a breakpoint and/or log statement in there and make sure that routine is getting called properly.)
这篇关于Swift如何使用新颜色填充叠加层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!