I am trying to implement a custom callout using MapBox
on iOS. When the user presses on the marker I would like a callout to display a UIWebView
rather than a left and right accessory view and the title with text only.
I have searched through the SDK documentation and cannot find a simple way to access the view of the annotation title so I can set it to a UIWebView
.
I started off by trying to access the annotation layer to see if I could make changes, such as:
RMAnnotation *annotation = [[RMAnnotation alloc] initWithMapView:mapView coordinate:CLLocationCoordinate2DMake(56.0,-4.0) andTitle:@"test"];
annotation.userInfo = @"test";
RMMapLayer *layer = annotation.layer;
layer.backgroundColor = [UIColor blackColor].CGColor;
However, when I press on the marker the annotation bubble is still white.
I have searched through the SDK to try to understand the relationship between the RMAnnotation
and RMMarker
classes and how they interact but think my understanding is flawed and hence I am not getting anywhere.
If anyone can help point me in the right direction that would be appreciated!
Ok, I figured out a way to make this work. Its a little of a 'hack' but it works really well for my purposes so I thought I would share. Please comment if you have a better idea and also tell me if this is not a great way to do it.
I checked the SDK source code and the
RMMapView
passes theSMCalloutView
object the title, subtitle and left/right accessory views. When I checked theSMCalloutView
code there is the ability to provide a custom callout by passing aUIView
tocontentView
, but theRMMapView
doesn't provide for passing this. My fix was to synthesize theSMCallout
(_currentCallout
) so that I can accesscontentView
from my ViewController and set contentView to aUIWebView
. I chose to create a new delegate method inRMMapViewDelegate
calledaboutToDisplayAnnotation
that provides me with the opportunity to swap in myUIWebView
before the callout is drawn to the screen, but I guess a better way might have been to rewrite theselectAnnotation
method inRMMapView
.