我创建了下面的视图,在这里我想在callOut中添加一个标题,但是我似乎不知道在哪里和如何做它。我想将它添加到注释中,它位于else if annotation.isKindOfClass(FBAnnotation)语句中。
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
var reuseId = ""
if annotation.isKindOfClass(FBAnnotationCluster) {
var reuseId = "Annonation"
reuseId = "Cluster"
var clusterView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
clusterView = FBAnnotationClusterView(annotation: annotation, reuseIdentifier: reuseId)
return clusterView
} else if annotation.isKindOfClass(FBAnnotation) {
let singleAnnotation = annotation as! FBAnnotation
reuseId = "Pin"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
pinView = FBSingleClusterView(annotation: annotation, reuseIdentifier: reuseId) as FBSingleClusterView
pinView!.image = UIImage(named: singleAnnotation.imageString)
pinView?.canShowCallout = false
let imagePinView = UIImageView(frame: CGRectMake(7.5, 7.5, pinView!.image!.size.width-15, pinView!.image!.size.width-15))
imagePinView.clipsToBounds = true
imagePinView.layer.cornerRadius = (pinView!.image!.size.width-15)/2
imagePinView.contentMode = UIViewContentMode.ScaleAspectFill
imagePinView.image = UIImage(data: singleAnnotation.logoImage)
pinView?.addSubview(imagePinView)
return pinView
} else {
return nil
}
}FBAnnotation
class FBAnnotation : NSObject {
var coordinate = CLLocationCoordinate2D()
var imageString = ""
var logoImage = NSData()
}
extension FBAnnotation : MKAnnotation {
}发布于 2015-10-24 09:39:11
看来你把canShowCallout设为假了。如果你想打个招呼的话,这应该是真的。
pinView?.canShowCallout = false还必须在MKAnnotation中设置title属性以使其在标注中显示。
MKAnnotation协议有一个标题,但它是可选的,所以您必须确保它是在自定义注释中实现的
class FBAnnotation : NSObject, MKAnnotation {
var coordinate = CLLocationCoordinate2D()
var imageString = ""
var logoImage = NSData()
var title: String?
var subtitle: String?
} 或
class FBAnnotation : NSObject {
var coordinate = CLLocationCoordinate2D()
var imageString = ""
var logoImage = NSData()
}
extension FBAnnotation : MKAnnotation {
var title: String?
var subtitle: String?
}https://stackoverflow.com/questions/33316561
复制相似问题