是否可以基于 URL 以编程方式为 MKPinAnnotationView 设置图像?到目前为止,我有这个:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
static NSString *identifier = @"infl8Node";
if ([annotation isKindOfClass:[infl8Node class]]) {
MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [_mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
} else {
annotationView.annotation = annotation;
}
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
annotationView.image = [UIImage imageNamed:@"invisible.png"];
annotationView.animatesDrop = YES;
//Add image from url
NSURL *url = [NSURL URLWithString: @"http://cdn2.raywenderlich.com/downloads/arrest.png"];
UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]];
UIImageView *imgView = [[UIImageView alloc] initWithImage:image];
[annotationView addSubview:imgView];
return annotationView;
}
return nil;
}
然而,它会导致这样的事情:
有没有人这样做或有一个好主意如何做到这一点?