作者:初学 | 来源:互联网 | 2023-08-13 08:47
IsitpossibletoprogrammaticallysettheimageforanMKPinAnnotationViewbasedonURL?SofarIh
Is it possible to programmatically set the image for an MKPinAnnotationView based on URL? So far I have this:
是否可以基于URL以编程方式为MKPinAnnotationView设置图像?到目前为止我有这个:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)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;
}
However it results in something like this:
但是它会产生这样的结果:
Has anyone done this or have a good idea as to how to accomplish this?
有没有人这样做或有一个好主意如何实现这一目标?
1 个解决方案