首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多个自定义点注解- Swift

多个自定义点注解- Swift
EN

Stack Overflow用户
提问于 2016-09-23 05:05:53
回答 2查看 1.6K关注 0票数 0

我正在尝试给我的两个MKPointAnnotation引脚一个自定义图像。到目前为止,我能够在两个引脚上显示相同的图像。我可以对下面的代码做些什么来给每个引脚一个自定义的图像?

代码语言:javascript
复制
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

        guard !(annotation is MKUserLocation) else {
            return nil
        }


        let annotationIdentifier = "AnnotationIdentifier"

        var annotationView: MKAnnotationView?

        if let dequeuedAnnotationView = mapView.dequeueReusableAnnotationView(withIdentifier: annotationIdentifier) {
            annotationView = dequeuedAnnotationView
            annotationView?.annotation = annotation
        }
        else {
            annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
            annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
        }


        if let annotationView = annotationView {
            annotationView.canShowCallout = true
            annotationView.image = UIImage(named: "Moto_pin")
        }

        return annotationView
    }
EN

回答 2

Stack Overflow用户

发布于 2016-09-23 05:08:20

您需要更改每个引脚的图像,而不是annotationView.image = UIImage(named: "Moto_pin")。该行将为每个注释视图分配相同的图像。

票数 0
EN

Stack Overflow用户

发布于 2016-09-23 05:31:46

尝试使用MKPinAnnotationView而不是MKAnnotationView。要做到这一点,你只需要改变:

MKPinAnnotationView annotationView: var?

使用这个类,你可以自定义大头针的颜色和整个视图

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39648864

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档