Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 具有自定义颜色和可见标题的MKMapView注释_Ios_Swift_Objective C_Xamarin.ios_Mkmapview - Fatal编程技术网

Ios 具有自定义颜色和可见标题的MKMapView注释

Ios 具有自定义颜色和可见标题的MKMapView注释,ios,swift,objective-c,xamarin.ios,mkmapview,Ios,Swift,Objective C,Xamarin.ios,Mkmapview,我知道我可以为MKPinAnnotationView设置自定义颜色 我还可以设置MKAnnotationView的标题,它不需要点击即可显示 但是我想要的是有一个既有自定义颜色又有可见标题的注释(而不是通过点击MKPinAnnotationView来显示标题) 这可能吗?您需要实现MKMAPViewDelegate并在下面重写此方法: func映射视图(\mapView:MKMapView,viewforannotation:MKAnnotation)->MKAnnotationView? 在该

我知道我可以为
MKPinAnnotationView
设置自定义颜色

我还可以设置
MKAnnotationView
的标题,它不需要点击即可显示

但是我想要的是有一个既有自定义颜色又有可见标题的注释(而不是通过点击
MKPinAnnotationView
来显示标题)


这可能吗?

您需要实现MKMAPViewDelegate并在下面重写此方法:

func映射视图(\mapView:MKMapView,viewforannotation:MKAnnotation)->MKAnnotationView?

在该方法中,只需实现如下内容:

 Avoid user location pin 
        if (annotation is MKUserLocation) {
            return nil
        } else {
    // HERE YOU CONFIGURE YOUR CUSTOM MKPinAnnotationView by also leveraging dequeue for performance
            let annotationIdentifier = "AnnotationIdentifier"

// YOUR CUSTOM VIEW you want to add instead of the default one
            let nibName = "MarkerView"
            let viewFromNib = Bundle.main.loadNibNamed(nibName, owner: self, options: nil)?.first as! MarkerView
            var annotationView: MarkerView?

            // if there is a view to be dequeued, use it for the annotation
            if let dequeuedAnnotationView = mapView.dequeueReusableAnnotationView(withIdentifier: annotationIdentifier) as? MarkerView {

                if dequeuedAnnotationView.subviews.isEmpty {
// HERE YOU ADD IT AS A SUBVIEW
                    dequeuedAnnotationView.addSubview(viewFromNib)
                }
                annotationView = dequeuedAnnotationView
                annotationView?.annotation = annotation
            } else {

                let av = MarkerView(annotation: annotation as? CustomPointAnnotation, reuseIdentifier: annotationIdentifier)
                av.addSubview(viewFromNib)
                annotationView = av 
            }
    ...
    ...
 ////// ETC ETC of the configuration after regarding your annotation view 
这应该可以回答您的问题。

有关Objective-C,请参阅。