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

Asked 2 years ago, Updated 2 years ago, 54 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.

UIButton*rightButton=[UIButtonButtonWithType:UIButtonTypeCustom];
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;
pinView.rightCalloutAccessoryView=rightButton;


2022-09-30 13:51

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.