Nach dem Apple-docs ist MKPinAnnotationView Stecknadel Farbe in den Farben rot, grün und lila. Gibt es eine Möglichkeit auch andere Farben zu bekommen? Ich habe nichts in der Dokumentation gefunden.
MKPinAnnotationView: Gibt es mehr als drei Farben zur Verfügung?
etwas mehr ;)
Alt-Text http://lionel.gueganton.free.fr/pins/pinGray.png

Alt-Text http://lionel.gueganton.free.fr/pins/pinOrange.png

Und die ursprüngliche:
Alt-Text http://lionel.gueganton.free.fr/pins/pinGreen.png

Alt-Text http://lionel.gueganton.free.fr/pins/pinPurple.png

Alt-Text http://lionel.gueganton.free.fr/pins/pinRed.png

Und der 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;
}
Sie können die folgenden Bilder nützlich finden:

und der Code sich in verwenden 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];
}
// ...
Sie könnten verwenden ZSPinAnnotationAnmerkung Pins auf der Fliege mit einem bestimmten zu erstellen UIColor: https://github.com/nnhubbard/ZSPinAnnotation
Ich mag Yonel die Antwort aber nur ein Heads - up, wenn Sie eine benutzerdefinierte MKAnnotationView erstellen, haben Sie manuell den Offset zuweisen. Für die Bilder Yonel zur Verfügung gestellt: (Sie können die calloutButton Sachen auslassen kann , wenn man diese nicht einer der Notwendigkeit)
#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;
}
Mit iOS 9, pinTintColorwurde hinzugefügt , um MKPinAnnotationView, so dass Sie eine Versorgung UIColorfür den Stift Farbe.
Und hier ist die PSD für den Stift mit Schatten und seine in @ 2x Größe.
http://dl.dropbox.com/u/5622711/ios-pin.psd
Verwenden Sie diese PSD für jede Farbe, die Sie wollen :)
Ich übernehme keine Gutschrift für diese PSD. Ich packte sie nur aus http://www.teehanlax.com/downloads/iphone-4-guid-psd-retina-display/ Sie haben einen tollen Job gemacht!
Weder der entsandten Lösungen arbeiten 100%, wenn Sie die Stecknadel fallen Animation verwenden. Cannonade Lösung ist sehr sauber, weil es sich der Stift immer noch erlaubt haben beide Arten von Enden (die scharfe Spitze bei Stürzen und die mit dem kreisförmigen Papier ripple), aber leider einen Blick auf die ursprüngliche Stiftkopffarbe gesehen werden kann, wenn der Stift prallt als trifft es auf die Karte. yonel die Lösung des gesamten Stift Bild zu ersetzen bedeutet, dass der Stift fällt mit dem kreisförmigen Papier Welligkeit, bevor es sogar die Karte schlagen!
Ich habe versucht, auf diese Weise, und es scheint in Ordnung zu sein ...
UIImage * image = [UIImage imageNamed:@"blue_pin.png"];
UIImageView *imageView = [[[UIImageView alloc] initWithImage:image]
autorelease];
[annotationView addSubview:imageView];
annotationView = nil;
mit dem kompletten Stift Bild ... als yonel Beispiel
Wenn es nicht in der Dokumentation ist dann höchstwahrscheinlich nicht, können Sie mkannotationview verwenden und ur eigenes Bild haben, wenn u obwohl wünschen













