自定义注释视图图像

时间:2014-08-23 17:13:58

标签: image swift mkmapview mkannotationview

我想自定义注释视图的图像。我试试这个:

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {

    //

    var lati: CLLocationDegrees = location.coordinate.latitude
    var longi: CLLocationDegrees = location.coordinate.longitude
    var locCoord:CLLocationCoordinate2D = CLLocationCoordinate2DMake(lati, longi)
    var point = MKPointAnnotation()
    point.coordinate = locCoord
    point.title = "Title"

    self.myMapView.addAnnotation(point)
    var anView:MKAnnotationView = mapView(self.myMapView, viewForAnnotation: point)

}

//{...}

func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
    if !(annotation is MKPointAnnotation) {
        return nil
    }

    let reuseId = "test"

    var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
    if anView == nil {
        anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
        anView.image = UIImage(named:"imageName")
        anView.canShowCallout = true
    }
    else {
        anView.annotation = annotation
    }

    return anView
}

但是我保留了Apple着名的Annotation pin而不是我的图像名为“imageName”。

我知道我MKPinAnnotationView来定制它。所以我刚做了MKAnnotationView。一个想法?

0 个答案:

没有答案