【发布时间】:2012-04-06 14:00:47
【问题描述】:
我想在我的MKMapView 中显示一张图片,而不是小rock pin。
有人可以在这里放一些有用的代码,或者告诉怎么做吗?
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
(id <MKAnnotation>)annotation {
MKPinAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil ) pinView = [[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:defaultPinID];
pinView.pinColor = MKPinAnnotationColorGreen;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
pinView.image = [UIImage imageNamed:@"pinks.jpg"]; //as suggested by Squatch
}
else {
[mapView.userLocation setTitle:@"I am here"];
}
return pinView;
}
我希望我的图像 pinks.jpg 出现在地图上,固定位置而不是默认的图钉视图(摇滚别针形状)。但我仍然得到了 pin 的默认图像。
【问题讨论】:
-
听起来你想要一个自定义注释。检查this tutorial。如果不适合您,谷歌搜索自定义注释教程也可以帮助您。
-
我猜 Annotation 只是 note 用来告知关于 pinned 位置的信息。但我想自定义图钉,将其图像更改为公司徽标。
-
我也尝试过你的tutorial方式,看来对我来说并不奏效。教程将
MKAnnotationView对象的image属性设置为一些UIImage。这是我测试过的,不会将 pinView 更改为我分配的图像。 -
@turtle,你能发布你尝试过的代码吗,会发生什么以及你期望什么?
-
@AnnaKarenina :我已经编辑了我的问题,你可以看看代码。谢谢..
标签: ios objective-c swift mkmapview mkannotation