簡體   English   中英

如何在iPhone中使用mkmapview中的兩個按鈕顯示自定義標注?

[英]How to show custom callout with two button in mkmapview in iPhone?

我想用兩個按鈕顯示一個自定義標注,我也想要對兩個按鈕進行操作,

在此輸入圖像描述

我嘗試了,但沒有在地圖上做這種類型的標注,這不是我想要的。 當我正在制作iPhone應用程序時,由於我是MKMapview的新手,因此我也很難做到這一點。 如何用兩個按鈕顯示自定義標注?

你可以去左右的calloutaccessoryview看看這里

//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;

}

同樣,您可以使用leftCalloutAccessoryView並添加另一個按鈕。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM