本文主要是介绍7.6 Displaying Custom Pins on a Map View,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
自定义pin
- (MKAnnotationView *)mapView:(MKMapView *)mapView
viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *result = nil;
if ([annotation isKindOfClass:[MyAnnotation class]] == NO)
{
return result;
}
if ([mapView isEqual:self.myMapView] == NO)
{
/* We want to process this event only for the Map View
that we have created previously */
return result;
}
/* First typecast the annotation for which the Map View has fired this delegate message */
MyAnnotation *senderAnnotation = (MyAnnotation *)annotation;
/* Using the class method we have defined in our custom annotation class, we will attempt to get a reusable identifier for the pin we are about to create */
NSString *pinReusableIdentifier = [MyAnnotation
reusableIdentifierforPinColor:senderAnnotation.pinColor];
/* Using the identifier we retrieved above, we will attempt to reuse a pin in the sender Map View */
MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:pinReusableIdentifier];
if (annotationView == nil){
/* If we fail to reuse a pin, then we will create one */
annotationView =[[MKPinAnnotationView alloc] initWithAnnotation:senderAnnotation
reuseIdentifier:pinReusableIdentifier];
/* Make sure we can see the callouts on top of each pin in case we have assigned title and/or subtitle to each pin */
annotationView.canShowCallout = YES;
}
UIImage *pinImage = [UIImage imageNamed:@"aa.jpg"];
NSLog(@"pingImage = %@",pinImage);
if (pinImage != nil){
annotationView.image = pinImage;
}
result = annotationView;
return result;
}
其他的同前一节
输出
这篇关于7.6 Displaying Custom Pins on a Map View的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!