ios - Swift 如何用新颜色填充叠加层

标签 ios swift mapkit overlay fill

我在填写叠加层时遇到问题。我想使用一种新颜色。我在这里先向您的帮助表示感谢。

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/

相关文章:

ios - 动态 Tableview 单元格

ios - 无法更改 iOS 13 中大标题的导航栏色调颜色

iOS同时使用CLLocation和MapView获取坐标和更新 map

ios - 无法从 UICollectionViewCell 中删除图像

ios - swift 错误 "Variable used within its own initial value"

ios - 用于 iOS 测试版应用程序分发的 Fabric Beta 与 Apple TestFlight?

iOS 从 iCloud Drive 下载文件

ios - 在 WatchOS2 中使用 NSURLSession 后台任务

ios - Swift 过滤对象数组中包含的相同位置坐标

swift - 计算 MKMapView 中 MKPolygon 的面积