How to set image on MKAnnotation in MKMapView

前端 未结 5 792
盖世英雄少女心
盖世英雄少女心 2021-01-06 23:53

I am developing an app for chating, I have to display all friends on a Map with their image. Please provide guidance to implement it.

I have used following code...

5条回答
  •  無奈伤痛
    2021-01-07 00:17

    try this code..just..

    annotationView.image=[UIImage imageNamed:@"red_point.png"];
    

    and remove annView.animatesDrop = TRUE; code

    - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation {
    
        //Define our reuse indentifier.
        static NSString *identifier = @"MapPoint";
    
    
        if ([annotation isKindOfClass:[MapPoint class]]) {
    
            MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [self.map dequeueReusableAnnotationViewWithIdentifier:identifier];
            if (annotationView == nil) {
                annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
                UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
                annotationView.leftCalloutAccessoryView=detailButton;
                annotationView.image=[UIImage imageNamed:@"red_point.png"];
    
            } else {
                annotationView.annotation = annotation;
            }
    
            annotationView.enabled = YES;
            annotationView.canShowCallout = YES;
    
            return annotationView;
        }
    
        return nil;
    }
    

    eidted:

     MKPinAnnotationView *annView = [[MKPinAnnotationView alloc]init]; 
    
         UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
              annView.leftCalloutAccessoryView=detailButton;
        annView.image=[UIImage imageNamed:@"Done.png"];
        annView.canShowCallout = YES;
        annView.calloutOffset = CGPointMake(-5, 5);
        [annView addSubview:imageView];
    

提交回复
热议问题