0

Hi I am trying to set a background image on my detail disclosure UIButton attached to my MapView MKAnnotation callout view. Checking on stackoverflow there are consistent examples of how to set this, however it doesn't seem to work for my callout UIButton. My question is, does this not work, simply because of the mapview or am I missing something else? Here is my code:

// If an existing pin view was not available, create one.
            pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomPinAnnotationView"];
            pinView.canShowCallout = YES;
            pinView.image = [UIImage imageNamed:@"Tch4"];
            //pinView.calloutOffset = CGPointMake(0, 32);
            pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
            UIImage *btnImage = [UIImage imageNamed:@"4stars"];
            [pinView.rightCalloutAccessoryView setBackgroundImage:btnImage forState:UIControlStateNormal];

I receive the error on the final line. Error is: No Visable interface for UIView declares the selector 'setbackgroundimage: forstate'

Thanks for your help with this

Kitcc
  • 648
  • 2
  • 8
  • 18

2 Answers2

1

Your problem is rightCalloutAccessoryView returns a UIView instance. And UIView does not respond to setBackgroundImage:forState: method.

What you are looking for is to add a UIButton instead something like this:

UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeCustom];
infoButton.frame = CGRectMake(0, 0, 32, 32); // Set your own frame 
[infoButton setBackgroundImage:btnImage forState:UIControlStateNormal];
[infoButton setBackgroundImage:btnImage forState:UIControlStateSelected];
pinView.rightCalloutAccessoryView = infoButton;
Abhinav
  • 36,284
  • 39
  • 178
  • 301
0

you cant set background image if your typebutton DetailDisclosure. you can addsubview image to rightCalloutAccessoryView but without button..

so if you still use typebutton DetailDisclosure you cant set background