how can I show an image in map pin annotation?

后端 未结 3 1419
谎友^
谎友^ 2021-02-06 17:58

i have one view >> subview mkmapview .

in that i want to show image . ...my current image is like this.\"alt

3条回答
  •  渐次进展
    2021-02-06 18:44

    v.leftCalloutAccessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img"]];
    

    where v - is the view of your annotation(MKAnnotationView) Or if you want complete solution - here it is:

    - (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id ) annotation{
    
        NSString *Identifier = [NSString stringWithFormat:@"%f%f",annotation.coordinate.latitude,annotation.coordinate.longitude];
        MKPinAnnotationView *annView= (MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:Identifier];
        if (annView==nil) {
            annView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:Identifier] autorelease];
        }
    
        if (![annotation isKindOfClass:[MyAnnotation class]]) {
            return nil;
        }
    
        RightCalloutAccessoryBtn* rightButton = [RightCalloutAccessoryBtn buttonWithType:UIButtonTypeDetailDisclosure];
        annView.rightCalloutAccessoryView = rightButton;
        annView.leftCalloutAccessoryView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img"]] autorelease];
        annView.canShowCallout = YES;
        return annView;
    }
    

    You should write this code on the class of your map's delegate

提交回复
热议问题