MKPinAnnotationView: ¿Hay más de tres colores disponibles?

votos
39

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 documentos.

Publicado el 26/07/2009 a las 22:32
fuente por usuario
En otros idiomas...                            


9 respuestas

votos
81

algo mas ;)

texto alternativo http://lionel.gueganton.free.fr/pins/pinGray.pngintroducir descripción de la imagen aquíintroducir descripción de la imagen aquí

texto alternativo http://lionel.gueganton.free.fr/pins/pinOrange.pngintroducir descripción de la imagen aquíintroducir descripción de la imagen aquí

Y los originales:

texto alternativo http://lionel.gueganton.free.fr/pins/pinGreen.png texto alternativo introducir descripción de la imagen aquí

texto alternativo http://lionel.gueganton.free.fr/pins/pinPurple.png texto alternativo introducir descripción de la imagen aquí

texto alternativo http://lionel.gueganton.free.fr/pins/pinRed.png texto alternativo introducir descripción de la imagen aquí

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;
}
Respondida el 14/01/2010 a las 19:24
fuente por usuario

votos
40

Puede que le resulte de utilidad las siguientes imágenes:

texto alternativo texto alternativo texto alternativo texto alternativo

y el código para utilizarlos 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];
    }
    // ...
Respondida el 26/12/2009 a las 15:09
fuente por usuario

votos
11

Se podría utilizar ZSPinAnnotationpara crear pasadores de anotación sobre la marcha con una especificada UIColor: https://github.com/nnhubbard/ZSPinAnnotation

Respondida el 19/01/2012 a las 19:57
fuente por usuario

votos
8

Me gustaría respuesta Yonel pero sólo una mano a mano, cuando se crea una costumbre MKAnnotationView, tendrá que asignar manualmente el desplazamiento. Para las imágenes de Yonel proporcionado: (se puede dejar de lado las cosas calloutButton si usted no necesita uno de esos)

#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;
}
Respondida el 31/05/2010 a las 18:59
fuente por usuario

votos
4

Con iOS 9, pinTintColorse ha agregado a MKPinAnnotationView, lo que le permite proporcionar una UIColorpara el color de alfiler.

Respondida el 14/10/2015 a las 10:29
fuente por usuario

votos
4

Y aquí está el PSD para el pin con sombra y su tamaño en @ 2x.

http://dl.dropbox.com/u/5622711/ios-pin.psd

Utilice esta PSD para cualquier color que usted quiere :)

Tomo ningún crédito para este PSD. Yo sólo lo agarré de http://www.teehanlax.com/downloads/iphone-4-guid-psd-retina-display/ Han hecho un trabajo maravilloso!

Respondida el 23/12/2011 a las 23:09
fuente por usuario

votos
3

Ninguna de las soluciones publicado trabajos 100% si está utilizando la animación caída de un alfiler. La solución de Cañoneo es muy ordenada, ya que permite que el pasador todavía tienen ambos tipos de extremos (la punta afilada cuando se caen y el que tiene la ondulación de papel circular), pero por desgracia una idea de la cabeza de color pin original se puede ver cuando los rebotes pin como se golpea el mapa. solución de reemplazar la imagen de pin conjunto de yonel significa el pasador cae con la ondulación del papel circular antes de que incluso se dio en el mapa!

Respondida el 30/11/2010 a las 21:39
fuente por usuario

votos
2

He intentado 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;

utilizando la imagen de pin completa ... como el ejemplo yonel

Respondida el 18/11/2010 a las 18:00
fuente por usuario

votos
1

Si no está en los documentos, entonces probablemente no, puede usar mkannotationview y tener su propia imagen si lo desea.

Respondida el 26/07/2009 a las 23:19
fuente por usuario

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more