gpt4 book ai didi

iphone - MKAnnotationView 自定义图像未显示

转载 作者:搜寻专家 更新时间:2023-10-30 19:55:11 26 4
gpt4 key购买 nike

我正在尝试添加自定义图像而不是 map 上的常规图钉。但它仍然是一个红色别针......我错过了什么?

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{  
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKPinAnnotationView *annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];
annView.animatesDrop = TRUE;
annView.image = [UIImage imageNamed:@"CustomPin.png"];
return annView;
}

最佳答案

MKMapView: Instead of Annotation Pin, a custom view

-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation 
{
MKAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil )
pinView = [[MKAnnotationView 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;
}

关于iphone - MKAnnotationView 自定义图像未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11829962/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com