iphone - MKAnnotationView 自定义图像未显示

标签 iphone objective-c cocoa-touch mkmapview mkannotationview

我正在尝试添加自定义图像而不是 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/

相关文章:

ios - 如何获取在 UIWebView 中显示的 HTML 页面的标题?

ios - 编码和解码函数如何使用 NSCoding 在 Swift 3 中工作?

ios - Iphone,获取 NSArray 中的国家/地区列表

iphone - UITextView修正建议如何移动到文字上方

ios - 如何在其他 ViewController 中继续下载数据

iphone - 如何在Interface Builder中查看UITableViewDelegate?

iphone - iOS Mobile Safari 纵向布局缩放过大

iphone - iOS 模拟器中的图像超出范围

objective-c - RestKit:嵌套数据但没有关系

objective-c - 在 obj-c (obj-c++) 模式下在 emacs 中的 header /实现之间切换缓冲区