Swift 单个自定义注释详图索引

Swift 单个自定义注释详图索引,swift,image,annotations,customization,callout,Swift,Image,Annotations,Customization,Callout,我正在创建一个包含自定义注释接点以及注释标注中的图像的地图。唯一的问题是,我无法找到一种方法来为不同的注释提供不同的图像。更具体地说,我在为注释标注创建单独的图像之后。虽然我已经找到了关于如何更改pin的结果,但我正在努力查找有关标注的任何信息,并将感谢任何帮助。下面是我正在使用的注释的函数。多谢各位 func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

我正在创建一个包含自定义注释接点以及注释标注中的图像的地图。唯一的问题是,我无法找到一种方法来为不同的注释提供不同的图像。更具体地说,我在为注释标注创建单独的图像之后。虽然我已经找到了关于如何更改pin的结果,但我正在努力查找有关标注的任何信息,并将感谢任何帮助。下面是我正在使用的注释的函数。多谢各位

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

    guard !annotation.isKind(of: MKUserLocation.self) else {
        return nil}

    let annotationIdentifier = "AnnotationIdentifier"

    var annotationView: MKAnnotationView?

    if let dequeuedAnnotationView = mapView.dequeueReusableAnnotationView(withIdentifier: annotationIdentifier) {
        annotationView = dequeuedAnnotationView
        annotationView?.annotation = annotation
    } else {
        let av = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
        av.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
        annotationView = av
    }

    if let annotationView = annotationView {
        // Configure your annotation view here
        annotationView.canShowCallout = true
        annotationView.image = UIImage(named: "pinAnnotation.png")
    }

    let imageName = "until.png"
    let image = UIImage(named: imageName)
    let imageView = UIImageView(image: image!)
    annotationView?.detailCalloutAccessoryView = imageView
    return annotationView
}


class ViewController2: UIViewController {

@IBOutlet var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()

//Location for first Pin
let locationOne = CLLocationCoordinate2DMake(-47.016945, 167.852095)

//Location for map centering
let locationNZ = CLLocationCoordinate2DMake(-43.937462, 170.507813)
let span = MKCoordinateSpanMake(9, 9)
let region = MKCoordinateRegion(center: locationNZ, span: span)
mapView.setRegion(region, animated: true)

//Create annotation one
let annotation = MKPointAnnotation()
annotation.coordinate = locationOne
annotation.subtitle = "Park"
annotation.title = "Rakiura National Park"

//Add annotation to the map
mapView.addAnnotation(annotation)

mapView.delegate = self}

在何处设置“注释”?注释在视图控制器类函数中设置。此链接显示的代码版本稍旧。请在问题中将该代码发布到。好的,问题中有代码,这是一个稍旧的版本,但格式相同。