开发者

How to customize the map annotation pin in MKMapView with iPhone?

开发者 https://www.devze.com 2023-03-26 06:58 出处:网络
Hello friends, I wan开发者_开发技巧t to develop a functionality MKMapView in iPhone and to show the custom pin in MKAnnotation so please could anyone provide me a link or any idea about this function

Hello friends,

I wan开发者_开发技巧t to develop a functionality MKMapView in iPhone and to show the custom pin in MKAnnotation so please could anyone provide me a link or any idea about this functionality.

Thanks in advance.


You would need to specify annotation image in the viewForAnnotation delegate method

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation {
        static NSString * const kAnnotationId = @"VumeliveAnnotation";

    MKPinAnnotationView *annotationView = nil;
    if ([annotation isKindOfClass:[CustomAnnotation class]])
    {
        annotationView = (MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:kAnnotationId];
        if (annotationView == nil) {
            annotationView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:kAnnotationId] autorelease];
            annotationView.canShowCallout = YES;
            annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        }

        [annotationView setImage:[UIImage imageNamed:<your image name>]];
    }

    return annotationView;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消