Can I use a custom view for SKCalloutView?
Is it possible to create a custom UIView with elements like Label and Button and use it like CalloutView?
What I have read in the documentation so far does not imply that this is possible.
It is possible to change the left and right buttons and also add a custom UIImageView for the arrow, but can't figure out if the whole view is really customizable.
+3
source to share
1 answer
Yes - you just need to override the calloutViewForAnnotation callback. The demo project has an example (see Inside AnnotationsViewController.m) where you can create a custom UIView and return it
- (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.
}
+3
source to share