1
我认为使用我自己的自定义图钉进行注释会非常容易。为什么我无法使用mapkit显示自定义注释引脚图像?
但我从来没有能够得到它的工作,我不知道为什么!
我只是用:
Annotation *anno = [[[Annotation alloc] init] autorelease];
anno.coordinate = ridesMap.userLocation.location.coordinate;
anno.title = @"Current Location";
anno.subtitle = [NSString stringWithFormat:@"%f, %f", anno.coordinate.latitude, anno.coordinate.longitude];
static NSString *defaultPinID = @"LocationIdentifier";
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[ridesMap dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (pinView == nil){
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:anno reuseIdentifier:defaultPinID] autorelease];
}
pinView.image = [UIImage imageNamed:@"custom_pin.png"];
pinView.opaque = NO;
pinView.canShowCallout = YES;
pinView.draggable = NO;
pinView.annotation = anno;
NSLog(@"Adding current location annotation");
return pinView;
我认为这应该工作,作为一个UIImage是它想要什么,我有我的项目中custom_pin.png文件。
它从来没有使用我的形象,但只是标准的红色别针。我在这里做错了什么?
是的!那就是诀窍。不知道我错过了这个!谢谢。 – 2010-06-22 14:00:25
这个答案为我节省了很多时间。不幸的是,SIMULATOR有一个BUG,甚至很难使用MKPinAnnotationView,模拟器向我展示了我设置的正确图像,只有设备没有向我显示图像。我开车疯了,直到我发现这篇文章。再次感谢。并且要小心,模拟器是你最大的敌人! :-) – 2014-06-25 09:17:51