Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MKPinAnnotationView: Are there more than three colors available?

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.

like image 356
Stefan Avatar asked Jul 26 '09 21:07

Stefan


2 Answers

some more ;)

alt text enter image description hereenter image description here

alt text enter image description hereenter image description here

And the original ones :

alt text alt textenter image description here

alt text alt textenter image description here

alt text alt textenter image description here

And the code:

- (MKAnnotationView*)mapView:(MKMapView*)mapView viewForAnnotation:(id <MKAnnotation>)annotation { MKPinAnnotationView* anView =[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"test"]; anView.pinColor=MKPinAnnotationColorPurple; UIImage* image = nil; // 2.0 is for retina. Use 3.0 for iPhone6+, 1.0 for "classic" res. UIGraphicsBeginImageContextWithOptions(anView.frame.size, NO, 2.0); [anView.layer renderInContext: UIGraphicsGetCurrentContext()]; image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); NSData* imgData = UIImagePNGRepresentation(image); NSString* targetPath = [NSString stringWithFormat:@"%@/%@", [self writablePath], @"thisismypin.png" ]; [imgData writeToFile:targetPath atomically:YES];  return anView; }  -(NSString*) writablePath { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; return documentsDirectory; } 
like image 59
yonel Avatar answered Oct 09 '22 03:10

yonel


You might find the following images useful:

alt textalt textalt textalt text

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];     }     // ... 
like image 35
RedBlueThing Avatar answered Oct 09 '22 01:10

RedBlueThing