SteBra
SteBra

Reputation: 4247

Is it possible to use custom view for SKCalloutView?

Is it possible to make a custom UIView, with elements such as Label and Button, and use it as a CalloutView?

What I read through the documentation so far doesn't implicates that it is possible.

Changing left and right button is possible, together with adding custom UIImageView for an arrow, but couldn't figure out if customising entire view is actually possible.

Upvotes: 3

Views: 273

Answers (1)

Ando
Ando

Reputation: 11409

Yes - you just have to override the calloutViewForAnnotation callback. There is an example in the demo project (see inside AnnotationsViewController.m) where you can create a user defined UIView and return that

- (UIView*)mapView:(SKMapView *)mapView calloutViewForAnnotation:(SKAnnotation *)annotation
{
    //Custom callouts.
    if (annotation.identifier == self.annotation1.identifier)
    {
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, 200.0f, 50.0f)];
        view.backgroundColor = [UIColor purpleColor];
        view.alpha = 0.5f;
        return view;
    }

    return nil;// Default callout view will be used.
}

Upvotes: 3

Related Questions