Skip to content

Instantly share code, notes, and snippets.

Created July 17, 2013 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6224519e308d6bf56c4c to your computer and use it in GitHub Desktop.
Save anonymous/6224519e308d6bf56c4c to your computer and use it in GitHub Desktop.
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
if ([annotation isKindOfClass:[PinLocation class]]) {
//MKAnnotationView *annotationView = (MKAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
static NSString *identifier = @"PinLocation";
MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeInfoLight];
//annotationView.animatesDrop = YES;
} else {
annotationView.annotation = annotation;
}
return annotationView;
}
else if ([annotation isKindOfClass:[ImagePin class]]){
static NSString *identifierImage = @"ImagePinLocation";
MKAnnotationView *annotationImageView = (MKAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier:identifierImage];
if(annotationImageView){
return annotationImageView;
}
else {
annotationImageView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifierImage];
annotationImageView.canShowCallout = YES;
annotationImageView.image = [UIImage imageNamed:@"image_bg_mappa"];
UIImage *frame = [UIImage imageNamed:@"image_bg_mappa"];
ImagePin *imagePinImage = annotation;
NSLog(@"%@", [NSString stringWithFormat:@"%@", imagePinImage.image]);
NSString *urlStringForImage = [NSString stringWithFormat:@"%@", imagePinImage.image];
NSURL *urlForImage = [NSURL URLWithString:urlStringForImage];
UIImageView *imageView = [[UIImageView alloc] init];
[imageView setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", urlForImage]] placeholderImage:[UIImage imageNamed:@"avatar-placeholder.png"]];
UIGraphicsBeginImageContext(CGSizeMake(annotationImageView.image.size.width, annotationImageView.image.size.height));
[frame drawInRect:CGRectMake(0, 0, frame.size.width, frame.size.height)];
[imageView.image drawInRect:CGRectMake(2, 2, 48, 38)]; // the frame your inner image
annotationImageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:@"" forState:UIControlStateNormal];
annotationImageView.canShowCallout = YES;
annotationImageView.rightCalloutAccessoryView = rightButton;
annotationImageView.enabled = YES;
annotationImageView.userInteractionEnabled = YES;
return annotationImageView;
}
}
else {
return nil;
}
}
@guru78
Copy link

guru78 commented Aug 25, 2013

how to show custom pin instead user picture ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment