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.
9 answers
Możesz znaleźć następujące obrazy przydatne:
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];
}
// ...
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.png
Alt text http://lionel.gueganton.free.fr/pins/pinOrange.png
I oryginalne:
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
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;
}
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
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;
}
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ę!
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.
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!
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
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
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