- (MKAnnotationView *)mapView:(MKMapView *)mapViewTmp viewForAnnotation:(id<MKAnnotation>)annotation
{
if(annotation == mapView.userLocation)
return nil;
MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mapViewTmp dequeueReusableAnnotationViewWithIdentifier:@"Pin"];
if (pinView ==nil) {
pinView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"Pin"];
{
if([addedAnns containsObject:annotation]){
MyAnnotation *a = [addedAnns objectAtIndex:[addedAnns indexOfObject:annotation]];
UIImage * image = [UIImage imageNamed:a.pinImage];
UIImageView *imageView = [[[UIImageView alloc] initWithImage:image] autorelease];
imageView.frame=[pinView bounds];
[pinView addSubview:imageView];
//[imageView release];
pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDeta`enter code here`ilDisclosure];
pinView.rightCalloutAccessoryView.tag = a.iAnnId;
[(UIButton *)pinView.rightCalloutAccessoryView addTarget:self action:@selector(openSpot:) forControlEvents:UIControlEventTouchUpInside];
pinView.enabled = YES;
pinView.centerOffset = CGPointMake(0,-15);
pinView.calloutOffset = CGPointMake(-8,0);
pinView.canShowCallout = YES;
}
}
pinView.animatesDrop = YES;
}
return pinView; // we cant release Or Auto release this object. Due To it will use futher
}
// The left accessory view to be used in the standard callout.
@property (retain, nonatomic) UIView *leftCalloutAccessoryView;
// The right accessory view to be used in the standard callout.
@property (retain, nonatomic) UIView *rightCalloutAccessoryView;
Как видите, я добавляю кнопку к rightCalloutAccessoryView
.Точно так же вы можете добавить изображения к нему.