void OnDidSelectAnnotationView(object sender, MKAnnotationViewEventArgs e) { // centralise map and freeze map updates MapPage.CentraliseMap(new Position(e.View.Annotation.Coordinate.Latitude, e.View.Annotation.Coordinate.Longitude)); MapPage.SetFreezeMap(true); // create custom callout with bus info // set background for callout var frame = new CGRect(0, 0, 200, 84); customPinView = new UIView { Frame = frame, BackgroundColor = new UIColor(0.8f, 0.8f, 0.8f, 0.3f), Center = new CGPoint(0, -(e.View.Frame.Height + 20)) }; customPinView.Layer.BorderColor = new CGColor(0, 0, 0, 50); customPinView.Layer.BorderWidth = 1f; customPinView.Layer.CornerRadius = 2f; // add text info customPinView.Add(new UILabel { Frame = frame, // title - label, subtitle - address (in xamarin.forms.maps) Text = e.View.Annotation.GetTitle() + "\n" + e.View.Annotation.GetSubtitle(), Font = UIFont.FromName("Helvetica", 12f), TextAlignment = UITextAlignment.Left, AdjustsFontSizeToFitWidth = true, LineBreakMode = UILineBreakMode.WordWrap, Lines = 0 }); e.View.AddSubview(customPinView); }
void OnDidDeselectAnnotationView(object sender, MKAnnotationViewEventArgs e) { if (!e.View.Selected) { customPinView.RemoveFromSuperview(); customPinView.Dispose(); customPinView = null; MapPage.SetFreezeMap(false); } }