Builds a MapKit Pin Annotation UIImage on the fly from a UIColor
Objective-C
Switch branches/tags
Nothing to show
Pull request Compare This branch is 34 commits behind nnhubbard:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
ZSPinAnnotation.xcodeproj
ZSPinAnnotation
Annotation.h
Annotation.m
README.md
ZSPinAnnotation.h
ZSPinAnnotation.m
color.png
color@2x.png
shading.png
shading@2x.png
stick.png
stick@2x.png

README.md

ZSPinAnnotation

Have you ever felt limited by the three Annotation pin colors that Apple provides with MapKit? Have you ever thought it was a pain to have to create custom images in photoshop every time you wanted to change the color? ZSPinAnnotation solves these problems by building the pin image on the fly. All you have to do is specify a UIColor and you get back a UIImage.

ZSPinAnnotation

How It Works

Create a ZSPinAnnotation:

UIImage *img = [ZSPinAnnotation pinAnnotationWithColor:[UIColor blueColor]];

Use a ZSPinAnnotation on a MapView:

- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation {
	
	if(![annotation isKindOfClass:[Annotation class]]) // Don't mess user location
        return nil;
	
	static NSString *defaultPinID = @"StandardIdentifier";
	MKAnnotationView *pinView = (MKAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
	if (pinView == nil){
		pinView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
		//pinView.animatesDrop = YES;
	}
	
	// Build our annotation
	if ([annotation isKindOfClass:[Annotation class]]) {
		Annotation *a = (Annotation *)annotation;
		pinView.image = [ZSPinAnnotation pinAnnotationWithColor:a.color];// ZSPinAnnotation Being Used
		pinView.annotation = a;
		pinView.enabled = YES;
		pinView.calloutOffset = CGPointMake(-11,0);
	}
	
	pinView.canShowCallout = YES;
	
	return pinView;
	
}//end

How to use in your App

ZSPinAnnotation requires the QuartzCore.framework.

Take a look at the demo project in the download to see how you can easily use the UIImages as MKMapView annotation images.

Notes

If you would like to help make ZSPinAnnotation even better feel free to contribute code or tweaked images.