Custom Callout Bubble iOS

后端 未结 3 581
眼角桃花
眼角桃花 2021-02-10 19:06

I am developing app with mapview functionality. I want to show custom pin image on mapview, click on that open custom callout bubble with image and title. With click on that cal

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-10 19:51

    Head over to CocoaControls for custom controls. I bet you'll find something useful for your requirement.

    Here are some search results from CocoaControls:

    • Callout
    • Bubble
    • Popup

    Custom Pin Image

    There are already questions on SO which answer this here and here and many more. I daresay you'll find your answer among them. Basically, the code is

    - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation
    {
        if([annotation isKindOfClass:[MKUserLocation class]])
        return nil;
    
        NSString *annotationIdentifier = @"CustomViewAnnotation";
        MKAnnotationView* annotationView = [mapview dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
        if(!annotationView)
        {
            annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation
                                                      reuseIdentifier:annotationIdentifier]];
        }
        annotationView.image = [UIImage imageNamed:@"map_location_pin.png"];
        annotationView.canShowCallout= YES;
    
        return annotationView;
    }
    

提交回复
热议问题