Je suis un développeur de noob to iphone et j'essaie d'ajouter un bouton personnalisé à une légende d'annotation. Je n'ai aucun problème à ajouter un bouton normal à rightCalloutAccessoryView, mais cela ne fonctionne pas pour le style personnalisé. Ma taille d'image est 32 x 32. Je veux aussi ajouter une broche de carte personnalisée suivant cette question stackoverflow here Toute aide est grandement appréciée.Comment ajouter un bouton/MapPin personnalisé à MKAnnotation?
MON CODE
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
// Define your reuse identifier.
static NSString *identifier = @"MapPoint";
if ([annotation isKindOfClass:[MapPoint class]]) {
MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
} else {
annotationView.annotation = annotation;
}
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
annotationView.animatesDrop = YES;
annotationView.image = [UIImage imageNamed:@"myimage.png"];
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
//UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setImage:[UIImage imageNamed:@"phony2.png"] forState:UIControlStateNormal];
[rightButton addTarget:self
action:@selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
annotationView.rightCalloutAccessoryView = rightButton;
return annotationView;
}
return nil;
}
Merci de votre réponse. J'ai essayé votre suggestion mais je n'ai toujours pas de chance. –
@B. Argent: Vous devez être plus précis que "ne pas avoir de chance". – Craig