I want to change the UIButton image displayed on the pin balloon of MKMap.

Asked 2 months ago, Updated 2 months ago, 3 views

The action is described in mapView:notationView:calloutAccessoryControlTapped: so that the action is taken when you click the callout now.

-(void)mapView:(MKMapView*)mapViewannouncementView:(MKAnnotationView*)announcementView calloutAccessoryControlTapped:(UIControl*)control{ 
    // processing

However, the button type displayed in pin.rightCalloutAccessoryView is

  • UIButtonTypeDetailDisclosure (i-mark)
  • UIButtonTypeContactAdd (+ mark)

There are only two types of , and they do not appear in UIButtonTypeCustom.

pinView.rightCalloutAccessoryView= UIButtonButtonWithType: UIButtonTypeDetailDisclosure;

How can I put my favorite button in the balloon and calloutAccessoryControlTapped:

ios objective-c mapkit

2022-09-30 13:51

1 Answers

The frame is probably zero, so it's actually added, but I can't see it (of course I can't even tap it).

Instead of generating and substituting it directly as it says, you can display the buttons of your choice by setting frame to change colors or set images if necessary.

rightButton.frame = CGRectMake (0.0, 0.0, 30.0, 30.0); // Specify the appropriate size here

// Also, change colors, set images, do whatever you want...
rightButton.backgroundColor=[UIColor blueColor];
rightButton setImage: UIImage imageNamed:@"flag" forState:UIControlStateNormal;

2022-09-30 13:51

If you have any answers or tips

© 2022 OneMinuteCode. All rights reserved.