MKPinAnnotationView: Are there more than three colors available?

前端 未结 9 1382

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:38

    some more ;)

    enter image description hereenter image description here

    enter image description hereenter image description here

    And the original ones :

    alt text enter image description here

    alt text enter image description here

    alt text enter image description here

    And the code:

    - (MKAnnotationView*)mapView:(MKMapView*)mapView viewForAnnotation:(id )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;
    }
    

提交回复
热议问题