Tuesday, 29 October 2013

Image as a left calloutaccessoryView


In native map annotation if you want to show custom image  in annotation and  discloser button as rightCalloutaccessoryView then you can do this by applying this code:


- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
  static NSString *AnnotationViewID = @"annotationViewID";
        
        MKAnnotationView *annotationView = (MKAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
        
        if (annotationView == nil)
        {
            annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] ;
        }
      annotationView.image = [UIImage imageNamed:@"marker.png"];
       UIImageView *_image_view = [[UIImageView alloc] initWithFrame:CGRectMake (0,0,31,31)];
       [_image_view setImage:[UIImage imageNamed:@"marker_similar.png"]];
       annotationView.leftCalloutAccessoryView = _image_view;
       annotationView.rightCalloutAccessoryView = [UIButton         buttonWithType:UIButtonTypeDetailDisclosure];
}




No comments:

Post a Comment