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,请参阅。