Creating Custom Call out View with button on it

匆匆过客 提交于 2019-12-11 21:52:54

问题


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:


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

}


来源:https://stackoverflow.com/questions/7978598/creating-custom-call-out-view-with-button-on-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!