How do I add custom pins to the iPhone MapKit?

后端 未结 4 423
小鲜肉
小鲜肉 2020-12-05 19:25

I\'m testing out the MapKit framework on the iPhone and would really much like to switch the standard pin that displays a location to an image called \"location.png\".

4条回答
  •  Happy的楠姐
    2020-12-05 19:51

    I solved it after looking at the source for MapCallouts

    Here is my solution:

    - (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id )annotation
    {
        static NSString *AnnotationViewID = @"annotationViewID";
    
        MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
    
        if (annotationView == nil)
        {
            annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
        }
    
        annotationView.image = [UIImage imageNamed:@"location.png"];
        annotationView.annotation = annotation;
    
        return annotationView;
    }
    

提交回复
热议问题