为什么我无法让 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 文件。
它从不使用我的图像,而只是使用标准的红色图钉。我在这里做错了什么?
I figured that using my own custom pin image for annotations would be super easy.
But I have never been able to get it to work, and I have no idea why!
I am simply using:
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;
I assumed that this should work, as a UIImage is what it is wanting, and I do have the custom_pin.png file in my project.
It never uses my image, but just the standard red pin. What am I doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自文档:
换句话说,MKPinAnnotationView 将忽略图像属性并始终显示图钉。请改用常规的
MKAnnotationView
。From the docs:
In other words, a MKPinAnnotationView will ignore the image property and always display a pin. Use a regular
MKAnnotationView
instead.