开发者

Custom MKMapPin image

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜