Podle dokumentů Apple, MKPinAnnotationView je pin barva je k dispozici v červené, zelené a fialové. Je nějaký způsob, jak získat další barvy také? Zjistil jsem nic docs.
MKPinAnnotationView: Existují více než tři barvy k dispozici?
něco víc ;)
alt textu http://lionel.gueganton.free.fr/pins/pinGray.png

alt textu http://lionel.gueganton.free.fr/pins/pinOrange.png

A ty původní:
alt textu http://lionel.gueganton.free.fr/pins/pinGreen.png

alt textu http://lionel.gueganton.free.fr/pins/pinPurple.png

alt textu http://lionel.gueganton.free.fr/pins/pinRed.png

A kód:
- (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;
}
Dalo by se najít tyto snímky užitečné:

a kód jejich použití v 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];
}
// ...
Dalo by se použít ZSPinAnnotationk vytváření poznámek kolíky za běhu se specifikovaným UIColor: https://github.com/nnhubbard/ZSPinAnnotation
Líbí se mi yonel odpověďmi , ale jen heads up, když si vytvořit vlastní MKAnnotationView, budete muset ručně přiřadit posun. U obrázků Yonel poskytovaných: (můžete vynechat calloutButton věci, pokud nepotřebujete jeden z nich)
#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;
}
S iOS 9, pinTintColorbyla přidána MKPinAnnotationView, což umožňuje dodávat UIColorpro barvu pin.
A tady je PSD pro pin se stínem a jejím v @ 2x velikosti.
http://dl.dropbox.com/u/5622711/ios-pin.psd
Použití tohoto PSD pro každou barvu, kterou chcete :)
Beru žádný úvěr pro tento PSD. Prostě jsem to vzal z http://www.teehanlax.com/downloads/iphone-4-guid-psd-retina-display/ Odvedli skvělou práci!
Ani jeden z vyslaných řešení fungovat na 100%, pokud používáte animace pin pokles. Kanonáda Řešení je velmi elegantní, protože umožňuje pin ještě oba druhy konců (ostrý hrot při pádu a ten s kruhovým papírové zvlnění), ale bohužel nahlédnout do původní barvy pin hlavy může být viděn, když pin skáče jako to udeří do mapy. Řešení yonel je nahradit celý pin obraz znamená, že pin padá s kruhovým papírové zvlnění než to dokonce zasáhla mapy!
Snažil jsem se sem a zdá se být v pořádku ...
UIImage * image = [UIImage imageNamed:@"blue_pin.png"];
UIImageView *imageView = [[[UIImageView alloc] initWithImage:image]
autorelease];
[annotationView addSubview:imageView];
annotationView = nil;
použitím kompletní pin image ... Jako příklad yonel
Pokud to není v docs pak s největší pravděpodobností ne, můžete použít mkannotationview a mají ur vlastní obraz, pokud u chtějí ačkoli













