我已在视图下方创建,我想在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 {
}
答案 0 :(得分:2)
似乎你将canShowCallout设置为false。如果你想要一个标注,这应该是真的。
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?
}