-
-
Save anonymous/6224519e308d6bf56c4c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to show custom pin instead user picture ?