MKPinAnnotationView: czy dostępne są więcej niż trzy kolory?

Zgodnie z dokumentami Apple, Kolor pin MKPinAnnotationView jest dostępny w kolorze czerwonym, zielonym i fioletowym. Czy jest jakiś sposób, aby uzyskać inne kolory również? Nic nie znalazłem w dokumentach.

Author: RedBlueThing, 2009-07-27

9 answers

Możesz znaleźć następujące obrazy przydatne:

alt textalt textalt textalt text

Oraz kod do ich użycia w 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];
    }
    // ...
 40
Author: RedBlueThing,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-02-08 14:18:50

Trochę więcej;)

Alt text http://lionel.gueganton.free.fr/pins/pinGray.pngTutaj wpisz opis obrazkaTutaj wpisz opis obrazka

Alt text http://lionel.gueganton.free.fr/pins/pinOrange.pngTutaj wpisz opis obrazkaTutaj wpisz opis obrazka

I oryginalne:

Alt text http://lionel.gueganton.free.fr/pins/pinGreen.png alt textTutaj wpisz opis obrazka

Alt text http://lionel.gueganton.free.fr/pins/pinPurple.png alt textTutaj wpisz opis obrazka

Alt text http://lionel.gueganton.free.fr/pins/pinRed.png alt textTutaj wpisz opis obrazka

I kod:

- (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;
}
 81
Author: yonel,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-04-15 19:53:29

Możesz użyć ZSPinAnnotation do tworzenia pinów adnotacji w locie z określonym UIColor: https://github.com/nnhubbard/ZSPinAnnotation

 11
Author: Nic Hubbard,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-01-19 18:57:15

Podoba mi się Yonel ' s Answer ale tylko uwaga, kiedy utworzysz Niestandardowy MKAnnotationView, będziesz musiał ręcznie przypisać offset. Do zdjęć, które Yonel dostarczył: (możesz pominąć rzeczy calloutButton, jeśli nie potrzebujesz jednego 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;
}
 8
Author: BadPirate,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:17:58

A oto PSD dla pinu z Shadowem i jego w rozmiarze @2x.

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

Użyj tego PSD na dowolny kolor:)

Nie przypisuję sobie tego PSD. Po prostu chwyciłem go z http://www.teehanlax.com/downloads/iphone-4-guid-psd-retina-display wykonali wspaniałą robotę!

 4
Author: Vashishtha Jogi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-12-23 22:09:39

W systemie iOS 9, pinTintColor został dodany do MKPinAnnotationView, co pozwala na podanie UIColor dla koloru Pina.

 4
Author: duncanc4,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-10-14 13:29:16

Żadne z opublikowanych rozwiązań nie działa w 100%, jeśli używasz animacji upuszczania pinów. Rozwiązanie canonade jest bardzo zgrabne, ponieważ pozwala szpilce nadal mieć oba rodzaje końcówek (ostry punkt podczas spadania i ten z okrągłym papierowym marszczeniem), ale niestety spojrzenie na oryginalny kolor główki szpilki można zobaczyć, gdy szpilka odbija się, gdy uderza w mapę. rozwiązanie yonela polegające na zastąpieniu całego obrazu pin oznacza, że pin spada z okrągłym papierowym marszczeniem, zanim jeszcze trafi w Mapa!

 3
Author: malhal,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-11-30 20:39:17

Próbowałem w ten sposób i wydaje mi się, że jest ok...

UIImage * image = [UIImage imageNamed:@"blue_pin.png"];
        UIImageView *imageView = [[[UIImageView alloc] initWithImage:image]
                                 autorelease];
        [annotationView addSubview:imageView];
        annotationView = nil;

Użycie pełnego obrazu Pina... jako przykład yonel

 2
Author: mt81,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-11-18 17:00:46

Jeśli nie ma go w dokumentach, to najprawdopodobniej nie, możesz użyć mkannotationview i mieć własny obraz, jeśli chcesz

 1
Author: Daniel,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-07-27 18:45:19