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];
}
// ...
精彩评论