自定义MKAnnotation的弹出气泡

13

我在我的应用程序地图页面上有一个要求,我必须自定义Callout气泡。我需要添加一个图片、两个标签和一个按钮,每个元素都有特定的高度和宽度。

我已经查看了网络,没有找到一个合适的链接来解释如何自定义Callout气泡。如果你们中的任何人遇到或知道,请与我分享。

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

提前感谢 suresh


可能是自定义注释视图的气泡的重复问题。 - Anurag
你好,Anurag。 那篇文章对我没有帮助。因为我不知道在哪里编写openForAnnotation事件以及如何在单击注释时连接视图。这对我来说不够清晰。我正在寻找更详细的解释。如果你知道,请告诉我。 - sbmandav
1个回答

21

一个帮助你的例子:

- (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;
}

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接