3

I want to show a custom callout with two button , and I also want action on both buttons ,

enter image description here

I try that but not do this type of callout on map, this isn't really exactly what I wanted. As I am making an iPhone application, Since I am new to MKMapview its getting difficult for me to do the same. How to show custom callout with two button?

Cœur
  • 37,241
  • 25
  • 195
  • 267
vijay
  • 1,235
  • 1
  • 11
  • 32

1 Answers1

0

You can go for Left and right calloutaccessoryview Look at HERE

//ANNOTATION VIEW SETTING DELEGATE
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
     MKPinAnnotationView *myPin  =   [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"reuseString"];
    myPin.draggable             =   NO;
    myPin.canShowCallout        =   YES;
    myPin.pinColor              =   MKPinAnnotationColorRed;

    UIButton *rightButton   =   [UIButton buttonWithType:UIButtonTypeCustom];
    rightButton.frame       =   CGRectMake(0, 0, 50, 30);
    [rightButton setTitle:@"Info!" forState:UIControlStateNormal];
    [rightButton setBackgroundImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal];
    rightButton.showsTouchWhenHighlighted   =   YES;
    [rightButton addTarget:self action:@selector(rightAcccoryViewButtonCLicked) forControlEvents:UIControlEventTouchUpInside]; //rightAcccoryViewButtonCLicked is a function

    myPin.rightCalloutAccessoryView = rightButton;

    return myPin;

}

Similarly you can use the leftCalloutAccessoryView and add another button.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
superGokuN
  • 1,399
  • 13
  • 28
  • hello sir , i try this code , in this have default callout , but i want big callout , in this callout have two button & one lable and i also want action on the both button , so please help me.... – vijay Jan 15 '13 at 09:41
  • @user1687868 with above approach you can achieve what you want a lable and two buttons with actions, but if you still need a bigger callout view than the default one, than you have to subclass the map annotation class here is a tutorial with source code http://webcache.googleusercontent.com/search?q=cache:0Yp2vE8AxWkJ%3ablog.asolutions.com/2010/09/building-custom-map-annotation-callouts-part-1/&hl=en&strip=1 – superGokuN Jan 15 '13 at 09:45