ios 自定义 MKAnnotation 标注气泡

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4094325/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 18:01:15  来源:igfitidea点击:

Customizing the MKAnnotation Callout bubble

iosobjective-ciphonemkmapviewmkannotation

提问by sbmandav

I have a requirement in my application map page. I have to customize the Callout bubbles. I need to add an image, two labels and a button with specific height and width of each.

我的应用程序地图页面中有一个要求。我必须自定义标注气泡。我需要添加一个图像、两个标签和一个具有特定高度和宽度的按钮。

I have gone through web and could not find a proper link that explains how to customize the callout bubbles. If any one of you come across or know about it please share with me.

我浏览了网络,但找不到解释如何自定义标注气泡的正确链接。如果你们中有人遇到或知道它,请与我分享。

any simple examples or links would be really great.

任何简单的示例或链接都非常棒。

Thanks in advance suresh

提前致谢

回答by MathieuF

An example to help you :

一个帮助你的例子:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{   
    MKAnnotationView *annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"loc"];

    // Button
    UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    button.frame = CGRectMake(0, 0, 23, 23);
    annotationView.rightCalloutAccessoryView = button;

    // Image and two labels
    UIView *leftCAV = [[UIView alloc] initWithFrame:CGRectMake(0,0,23,23)];
    [leftCAV addSubview : yourImageView];
    [leftCAV addSubview : yourFirstLabel];
    [leftCAV addSubview : yourSecondLabel];
    annotationView.leftCalloutAccessoryView = leftCAV;

    annotationView.canShowCallout = YES;

    return annotationView;
}

For more informations, look at this : http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKAnnotationView_Class/Reference/Reference.html%23//apple_ref/occ/cl/MKAnnotationView

有关更多信息,请查看:http: //developer.apple.com/library/ios/#documentation/MapKit/Reference/MKAnnotationView_Class/Reference/Reference.html%23//apple_ref/occ/cl/MKAnnotationView