Reputation: 5232
I am working on a map application. I am done with fetching locations on certain conditions, showing annotation on map view and displaying my custom callout bubble.
My requirement is to display the annotation pin as follow:
Now I know I can set Image to the annotation view and make it rounded corner as follow:
pinView.image = [UIImage imageNamed:@"annotationImage"];
[pinView.layer setCornerRadius:8.0];
[pinView setClipsToBounds:YES];
Here pinView
is an AnnotationView.
Please let me know if I can create a custom view and assign it to pin view so I can get the red badge and set Image as well.
UPDATE
I tried lot more things and got succeed to put the view. But the problem is if I use a MKAnnotationView
object on map I am not able to tap it or call gesture recognizer on it. If I use MKPinAnnotationView
than I am able to call didSelected method or add a gesture recognizer but I am not able to set a Image on it as it is a Pin Annotation.
Plz let me know if this is possible.
Thanks in advance.
Upvotes: 0
Views: 5928
Reputation: 2122
you need to set your Class as MKMapViewDelegate
and fill this method:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
CustomMapAnnotationView *annotationView = nil;
pinView.image = [UIImage imageNamed:@"annotationImage"];
[pinView.layer setCornerRadius:8.0];
[pinView setClipsToBounds:YES];
NSString* identifier = @"CustomMapAnnotation";
CustomMapAnnotationView *newAnnotationView = (CustomMapAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if(nil == newAnnotationView) {
newAnnotationView = [[[CustomMapAnnotationView alloc] initWithAnnotation: pinView reuseIdentifier:identifier] autorelease];
}
annotationView = newAnnotationView;
[annotationView setEnabled:YES];
[annotationView setCanShowCallout:YES];
return annotationView;
}
Thus, you can return a custom Class, subclass of MKAnnotationView
, and you can add badge now to your custom view.
Upvotes: 3