【问题标题】:Change Pin's color in MapKit - Swift 4 - Xcode 10 - iOS 12在 MapKit 中更改 Pin 的颜色 - Swift 4 - Xcode 10 - iOS 12
【发布时间】:2018-10-18 14:14:43
【问题描述】:

我正在尝试在 Xcode 的 MapKit 中更改我的地图中使用的图钉的颜色。我在 Apple 开发者文档中找到了这个:

声明(iOS、tvOS):

var pinTintColor: UIColor! { get set }

我是编码新手,不知道应该在 get 和 set 中输入什么,请您帮帮我吗?

谢谢!

【问题讨论】:

  • 你应该在你的代码周围添加一些上下文,它会帮助用户帮助你:-)
  • 你不能只使用'yourPin.pinTintColor = .red'吗?
  • 不幸的是,这种技术不再有效。

标签: ios swift mapkit mapkitannotation


【解决方案1】:

试试下面的代码:

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    if annotation is MKUserLocation {
        return nil
    }

    let reuseId = "pin"
    var pinView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId) as? MKPinAnnotationView
    if pinView == nil {
        pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
        pinView?.pinTintColor = .purple

    }
    else {
        pinView?.annotation = annotation
    }

    return pinView
}

【讨论】:

  • 谢谢,但它对我不起作用,但我可能做错了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多