Add image behind MKPinAnnotationView

后端 未结 3 951
南笙
南笙 2021-02-04 22:05

I\'m trying to add an image behind a MKPinAnnotationView. Seems like it should be rather easy to just do this in here:

- (void)mapView:(MKMapView *)mapView didAd         


        
3条回答
  •  半阙折子戏
    2021-02-04 22:42

    Thanks for the input, here's basically what I ended up doing without subclassing:

    - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation {
    
        MKAnnotationView *annView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
    
        UIImage *image = [UIImage imageNamed:@"image.png"];
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        [annView addSubview:imageView];
        [imageView release];
    
        MKPinAnnotationView *pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];     
        [annView addSubview:pinView];
        [pinView release];
    
        return annView;
    }
    

    I only needed one pin, so I set reuseIdentifier to nil.

提交回复
热议问题