gpt4 book ai didi

ios - 快速向 callOut View 添加标题

转载 作者:搜寻专家 更新时间:2023-11-01 07:29:49 24 4
gpt4 key购买 nike

我创建了下面的 View ,我想在 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 {

}

最佳答案

您似乎将 canShowCallout 设置为 false。如果您想要标注,这应该是正确的。

pinView?.canShowCallout = false

您还必须在 MKAnnotation 中设置 title 属性以使其显示在标注中。

MKAnnotation 协议(protocol)有一个标题,但它是可选的,因此您必须确保它已在您的自定义注释中实现

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?
}

关于ios - 快速向 callOut View 添加标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33316561/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com