MKPinAnnotationView: Are there more than three colors available?

前端 未结 9 1264

According to the Apple docs, MKPinAnnotationView\'s pin color is available in red, green and purple. Is there any way to get other colors also? I\'ve found nothing in the do

相关标签:
9条回答
  • 2020-11-27 10:18

    With iOS 9, pinTintColor has been added to MKPinAnnotationView, allowing you to supply a UIColor for the pin color.

    0 讨论(0)
  • 2020-11-27 10:25

    You could use ZSPinAnnotation to create annotation pins on the fly with a specified UIColor: https://github.com/nnhubbard/ZSPinAnnotation

    0 讨论(0)
  • 2020-11-27 10:25

    Neither of the posted solutions work 100% if you are using the pin drop animation. Cannonade's solution is very neat because it allows the pin to still have both kinds of ends (the sharp point when falling and the one with the circular paper ripple) but unfortunately a glimpse of the original pin head colour can be seen when the pin bounces as it hits the map. yonel's solution of replacing the whole pin image means the pin falls with the circular paper ripple before it's even hit the map!

    0 讨论(0)
  • 2020-11-27 10:27

    I tried this way and it seems to be ok...

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

    using the complete pin image... as the yonel example

    0 讨论(0)
  • 2020-11-27 10:29

    You might find the following images useful:

    alt text alt text alt text alt text

    and the code to use them in 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];
        }
        // ...
    
    0 讨论(0)
  • 2020-11-27 10:30

    And here is the PSD for the pin with shadow and its in @2x size.

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

    Use this PSD for any color you want :)

    I take no credit for this PSD. I just grabbed it from http://www.teehanlax.com/downloads/iphone-4-guid-psd-retina-display/ They have done a wonderful job!

    0 讨论(0)
提交回复
热议问题