3

这就是我在 MapKit 上添加注释的方式:

 MKPointAnnotation *point = [[MKPointAnnotation alloc] init];

    point.coordinate = zoomLocation;
    point.title = @"Where am I?";
    point.subtitle = @"I'm here!!!";


    [self.mapView addAnnotation:point ];

怎样才能改变注解的图像?

4

2 回答 2

1

创建自定义注释类。

CustomAnnotation.h

#import <MapKit/MapKit.h>

@interface CustomAnnotation : MKAnnotationView

@end

CustomAnnotation.m

#import "CustomAnnotation.h"

@implementation CustomAnnotation

-(id)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier    {

    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
    if (self != nil) {
        CGRect frame = self.frame;
        frame.size = CGSizeMake(46.0, 49.0);
        self.frame = frame;
        self.backgroundColor = [UIColor clearColor];
        self.centerOffset = CGPointMake(-5, -5);
    }
    return self;
}


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
    [[UIImage imageNamed:@"IMAGE_NAME"] drawInRect:rect];

}

在我们的 mapview 委托方法viewForAnnotation

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation  {


    static NSString *defaultPinId = @"Pin";
    CustomAnnotation *pinView = (CustomAnnotation *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinId];

    if (pinView == nil) {

        pinView = [[CustomAnnotation alloc]initWithAnnotation:annotation reuseIdentifier:defaultPinId];

    }
    else    {
        pinView.annotation = annotation;
    }

    return pinView;

}
于 2013-10-24T08:33:13.620 回答
0

尝试这个,

MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
[[self.mapView viewForAnnotation:point] setTag:1];
UIImage *image = [UIImage imageNamed:@"pinIcon.png"];
[[self.mapView viewForAnnotation:point] setImage:image];
于 2013-10-24T08:28:15.387 回答