According to the Apple docs, MKPinAnnotationView's pin color is available in red, green and purple. Is there any way to get other colors also? I've found nothing in the docs.
+1
A:
If it's not in the docs then most probably not, you cAn use mkannotationview and have ur own image if u wish though
Daniel
2009-07-26 22:19:06
+7
A:
You might find the following images useful:
and the code to use them in viewForAnnotation:
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
// ... get the annotation delegate and allocate the MKAnnotationView (annView)
if ([annotationDelegate.type localizedCaseInsensitiveCompare:@"NeedsBluePin"] == NSOrderedSame)
{
UIImage * image = [UIImage imageNamed:@"blue_pin.png"];
UIImageView *imageView = [[[UIImageView alloc] initWithImage:image] autorelease];
[annView addSubview:imageView];
}
// ...
Cannonade
2009-12-26 14:09:57
Nice, thank you :-)
Stefan
2010-01-11 15:37:26
No problem. Glad you found them useful.
Cannonade
2010-01-11 21:35:00
Hi, how did you get the original pins? Thanks. Are there @2x versions available?
matt
2010-07-20 12:16:15
I ran a piece of code in the simulator that writes the UIImage to the file system using UIImagePNGRepresentation(yourImage). Image -> NSData -> fileSystem. I don't have the @2x versions available :/
yonel
2010-08-08 20:29:06
matt, I added the retina display for the pins. and also the code used to render them.
yonel
2010-09-07 09:32:32
+1
A:
I like Yonel's Answer but just a heads up, when you create a custom MKAnnotationView, you'll have to manually assign the offset. For the images Yonel provided: (you can leave out the calloutButton stuff if you don't need one of those)
#pragma mark MKMapViewDelegate
- (MKAnnotationView *)mapView:(MKMapView *)aMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if(![annotation isKindOfClass:[MyAnnotation class]]) // Don't mess user location
return nil;
MKAnnotationView *annotationView = [aMapView dequeueReusableAnnotationViewWithIdentifier:@"spot"];
if(!annotationView)
{
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"spot"];
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[(UIButton *)annotationView.rightCalloutAccessoryView addTarget:self action:@selector(openSpot:) forControlEvents:UIControlEventTouchUpInside];
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
annotationView.centerOffset = CGPointMake(7,-15);
annotationView.calloutOffset = CGPointMake(-8,0);
}
// Setup annotation view
annotationView.image = [UIImage imageNamed:@"pinYellow.png"]; // Or whatever
return annotationView;
}
BadPirate
2010-05-31 17:59:49