MKPinAnnotationView: ¿Hay más de tres colores disponibles?
De acuerdo con los documentos de Apple, el color del pin de MKPinAnnotationView está disponible en rojo, verde y morado. ¿Hay alguna manera de obtener otros colores también? No he encontrado nada en los médicos.
9 answers
Puede que le sean útiles las siguientes imágenes:
Y el código para usarlos en 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];
}
// ...
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-02-08 14:18:50
Algo más;)
Texto alternativo http://lionel.gueganton.free.fr/pins/pinGray.png
Texto alternativo http://lionel.gueganton.free.fr/pins/pinOrange.png
Y los originales :
Texto alternativo http://lionel.gueganton.free.fr/pins/pinGreen.png
Texto alternativo http://lionel.gueganton.free.fr/pins/pinPurple.png
Texto alternativo http://lionel.gueganton.free.fr/pins/pinRed.png
Y el código:
- (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;
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-04-15 19:53:29
Podría usar ZSPinAnnotation
para crear pines de anotación sobre la marcha con un UIColor
: https://github.com/nnhubbard/ZSPinAnnotation
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-01-19 18:57:15
Me gusta La respuesta de Yonel pero solo un aviso, cuando cree un MKAnnotationView personalizado, tendrá que asignar manualmente el desplazamiento. Para las imágenes que Yonel proporcionó: (puede omitir las cosas de calloutButton si no necesita una de esas)
#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;
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:17:58
Y aquí está el PSD para el pin con sombra y su tamaño @2x.
Http://dl.dropbox.com/u/5622711/ios-pin.psd
Utilice este PSD para cualquier color que desee :)
No tomo ningún crédito por este PSD. Me agarró de http://www.teehanlax.com/downloads/iphone-4-guid-psd-retina-display/ Que han hecho un trabajo maravilloso!
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-12-23 22:09:39
Con iOS 9, se ha agregado pinTintColor
a MKPinAnnotationView
, lo que le permite proporcionar un UIColor
para el color del pin.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-14 13:29:16
Ninguna de las soluciones publicadas funciona al 100% si está utilizando la animación de caída de pines. La solución de Cannonade es muy ordenada porque permite que el alfiler todavía tenga ambos tipos de extremos (el punto afilado al caer y el que tiene la ondulación de papel circular), pero desafortunadamente se puede ver un vistazo del color original de la cabeza del alfiler cuando el alfiler rebota al golpear el mapa. la solución de yonel de reemplazar toda la imagen del alfiler significa que el alfiler cae con la ondulación de papel circular antes de que siquiera llegue al mapa!
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-11-30 20:39:17
Lo intenté de esta manera y parece estar bien...
UIImage * image = [UIImage imageNamed:@"blue_pin.png"];
UIImageView *imageView = [[[UIImageView alloc] initWithImage:image]
autorelease];
[annotationView addSubview:imageView];
annotationView = nil;
Usando la imagen pin completa... como el ejemplo de yonel
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-11-18 17:00:46
Si no está en los documentos, lo más probable es que no, puede usar mkannotationview y tener su propia imagen si lo desea
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-07-27 18:45:19