【发布时间】:2016-02-11 15:06:38
【问题描述】:
我必须为不同的引脚设置自定义图像。使用我的代码,我可以为它们中的每一个设置自定义颜色,但是当我尝试设置自定义图像而不是颜色时,它不起作用。
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(MyAnnotation *)annotation {
static NSString *identifier = @"MyLocation";
if ([annotation isKindOfClass:[MyAnnotation class]]) {
MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[self.myMap dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
} else {
annotationView.annotation = annotation;
}
annotationView.enabled = YES;
annotationView.canShowCallout = NO;
NSString *stringType = [NSString stringWithFormat:@"%@", [(MyAnnotation *)annotationView.annotation stringType]];
if ([stringType isEqualToString:@"0"]) {
annotationView.image = [UIImage imageNamed:@"IconUserCerco.png"];
//annotationView.pinColor = MKPinAnnotationColorGreen;
} else if ([stringType isEqualToString:@"1"]) {
annotationView.image = [UIImage imageNamed:@"IconUserDefault.png"];
//annotationView.pinColor = MKPinAnnotationColorPurple;
} else if ([stringType isEqualToString:@"2"]) {
annotationView.image = [UIImage imageNamed:@"PinUniversity.png"];
//annotationView.pinColor = MKPinAnnotationColorRed;
}
return annotationView;
}
return nil;
}
任何帮助将不胜感激。提前致谢。
【问题讨论】:
标签: ios xcode mkmapview mkpinannotationview