开发者

Custom MKMapPin image

开发者 https://www.devze.com 2023-02-16 07:23 出处:网络
I just wanted to quickly开发者_JAVA技巧 ask how I could use an image as my MKMapPin.In the viewForAnnotation method, create an MKAnnotationView (not an MKPinAnnotationView) and set its image property.

I just wanted to quickly开发者_JAVA技巧 ask how I could use an image as my MKMapPin.


In the viewForAnnotation method, create an MKAnnotationView (not an MKPinAnnotationView) and set its image property.


Also you can subclass mkannotationview to add more functionality.


You need to add the following code to your viewForAnnotation message:

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{   
    // ... get the annotation delegate and allocate the MKAnnotationView (annView)
    if ([annotationDelegate.type localizedCaseInsensitiveCompare:@"needs_your_image"] == NSOrderedSame)
    {
        UIImage * image = [UIImage imageNamed:@"your_image_here.png"];
        UIImageView *imageView = [[[UIImageView alloc] initWithImage:image] autorelease];
        [annView addSubview:imageView];
    }
    // ...
0

精彩评论

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