Creating Custom Call out View with button on it

2019-08-27 17:13发布

I am stuck with a map View problem for which I was surfing the internet from the last three days but still not find any appropiate solution.

My problem is When I click on my pin which is customized, a callout appears. But standard callout support only two lines text.In my case I have to show four lines text with a button. Please any one tell me how to create a custom callout or what approach should I use as there is no way to modify the standard callout.

Any suggestions would be highly appreciated. Thanks in advance.

1条回答
祖国的老花朵
2楼-- · 2019-08-27 17:59

In your delegate method

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    MKAnnotationView* annotationView = nil;

    //your code

        UIView *vw = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
        vw.backgroundColor = [UIColor redColor];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 50, 50)];
        label.numberOfLines = 4;
        label.text = @"hello\nhow are you\nfine";
        [vw addSubview:label];
        annotationView.leftCalloutAccessoryView = vw;
        return annotationView

}
查看更多
登录 后发表回答