如题
代码:
customAnnotation.h
@interface customAnnotation : NSObject <MKAnnotation>
{
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
}@property (nonatomic, readonly)CLLocationCoordinate2D coordinate;
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *subtitle;
-(id)initCustomeAnnotation:(CLLocationCoordinate2D)coords;customAnnotation.m
@implementation customAnnotation
@synthesize coordinate, title, subtitle;-(id)initCustomeAnnotation:(CLLocationCoordinate2D)coords{

if (self = [super init]){
coordinate = coords;
}

return self;
}
-(void)dealloc{
[self.title release];
[self.subtitle release];
[super dealloc];
}
@endviewController.m@implementation ipadMapViewController-(MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation{ MKPinAnnotationView *pinView = (MKPinAnnotationView *)[theMapView dequeueReusableAnnotationViewWithIdentifier:annotation.title];

if (pinView == nil){
pinView = [[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:annotation.title] autorelease];
pinView.animatesDrop = YES;
pinView.canShowCallout = YES;
pinView.pinColor = MKPinAnnotationColorGreen;
}
else {
pinView.annotation = annotation;
} NSLog(@"set green");
return pinView;
}-(IBAction) buttonPressed:(id)sender{

CLLocationCoordinate2D coords;
coords.latitude = 37.331689;
coords.longitude = 122.030731;
float zoomLevel = 0.018;

MKCoordinateRegion region = MKCoordinateRegionMake(coords, MKCoordinateSpanMake(zoomLevel, zoomLevel));
[pmapView setRegion:[pmapView regionThatFits:region] animated:YES];

customAnnotation *annotation = [[customAnnotation alloc] initCustomeAnnotation:coords];
annotation.title = @"Apple";
annotation.subtitle = @"Subtitle";

[pmapView addAnnotation:annotation];
[annotation release];
}
…………@end
大头针的颜色不变,掉下来的效果也出不来